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
ln -s ${PWD}/rkhunter.sh /etc/cron.daily
</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
# Checks mailQ size
QUEUELIMIT=0
HOST=$(/bin/hostname)
QUEUELENGTH=$(/usr/sbin/postqueue -p | tail -n1 | awk '{print $5}')
QUEUECOUNT=$(echo $queuelength | grep "[0-9]")
QUEUELIMIT=75
SUBJECT="Mail Queue on $HOST is currently $QUEUECOUNT"
MAILTO="mmckinnon@comprofix.com"
HOST=$(/bin/hostname)
POSTQUEUE=$(which postqueue)
QUEUELENGTH=$($POSTQUEUE -p | tail -n1 | awk '{print $5}')
QUEUECOUNT=$(echo $QUEUELENGTH | grep "[0-9]")
if [ "$QUEUECOUNT" == "" ]; then
exit;
elif [ "$QUEUECOUNT" -gt "$QUEUELIMIT" ]; then
#echo $msg | /bin/mail -s "Mail Queue Alert $queuecount ($hostname)" "helpdesk@ambient-it.com.au"
/usr/sbin/postqueue -p | /bin/mail -s "$SUBJECT" "$MAILTO"
$POSTQUEUE -p | /bin/mail -s "$SUBJECT" "$MAILTO"
fi