一个清理postfix邮件队列中无效收件人邮件的shell脚本。
复制代码代码示例:
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH STATUS_OK="Mail queue is empty" STATUS=`postqueue -c /etc/postfix -p` MAIL_INFO=`postqueue -c /etc/postfix -p|grep '@'` if [ "${STATUS_OK}" != "${STATUS}" ] then for i in `postqueue -c /etc/postfix -p |grep -P '(\d+\:){2}\d+' |awk '{print $1}'` do if echo "$i" |grep -vq '*' then echo "${MAIL_INFO}" >>/opt/mail.log sudo postsuper -d $i fi done fi
创建定时计划任务:
复制代码代码示例:
crontab
*/5 * * * * /opt/mail.sh &> /dev/null 每五分钟清理一次。 |