Added mailQWatch.sh for mailq reporting

Updated README.md with instructions
This commit is contained in:
Matthew McKinnon 2016-06-06 22:41:18 +10:00
parent b323ab96db
commit bb95025e81
2 changed files with 31 additions and 11 deletions

20
README.md Normal file → Executable file
View File

@ -98,3 +98,23 @@ Script sends an email with the rkhunter scan and report.
apt-get install rkhunter apt-get install rkhunter
ln -s ${PWD}/rkhunter.sh /etc/cron.daily ln -s ${PWD}/rkhunter.sh /etc/cron.daily
</code></pre> </code></pre>
#### mailQWatch.sh
Script checks mailq size on a postfix system and sends an email when queue size is greater than threshold.
Update variables in scripts to suit your needs.
<pre><code>
QUEUELIMIT=75
SUBJECT="Mail Queue on $HOST is currently $QUEUECOUNT"
MAILTO="user@example.com"
</code></pre>
<b>Installation</b>
As root, sudo will not work.
<pre><code>
echo "*/5 * * * * ${PWD}/mailQWatch.sh" >> /etc/crontab
</code></pre>

View File

@ -1,16 +1,16 @@
#!/bin/bash #!/bin/bash
# Checks mailQ size
QUEUELIMIT=75
QUEUELIMIT=0 SUBJECT="Mail Queue on $HOST is currently $QUEUECOUNT"
HOST=$(/bin/hostname) MAILTO="mmckinnon@comprofix.com"
QUEUELENGTH=$(/usr/sbin/postqueue -p | tail -n1 | awk '{print $5}')
QUEUECOUNT=$(echo $queuelength | grep "[0-9]") HOST=$(/bin/hostname)
SUBJECT="Mail Queue on $HOST is currently $QUEUECOUNT" POSTQUEUE=$(which postqueue)
MAILTO="mmckinnon@comprofix.com" QUEUELENGTH=$($POSTQUEUE -p | tail -n1 | awk '{print $5}')
QUEUECOUNT=$(echo $QUEUELENGTH | grep "[0-9]")
if [ "$QUEUECOUNT" == "" ]; then if [ "$QUEUECOUNT" == "" ]; then
exit; exit;
elif [ "$QUEUECOUNT" -gt "$QUEUELIMIT" ]; then elif [ "$QUEUECOUNT" -gt "$QUEUELIMIT" ]; then
#echo $msg | /bin/mail -s "Mail Queue Alert $queuecount ($hostname)" "helpdesk@ambient-it.com.au" $POSTQUEUE -p | /bin/mail -s "$SUBJECT" "$MAILTO"
/usr/sbin/postqueue -p | /bin/mail -s "$SUBJECT" "$MAILTO"
fi fi