diff --git a/README.md b/README.md old mode 100644 new mode 100755 index fc2486b..8a9504a --- a/README.md +++ b/README.md @@ -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 + +#### 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. + +
+QUEUELIMIT=75
+SUBJECT="Mail Queue on $HOST is currently $QUEUECOUNT"
+MAILTO="user@example.com"
+
+
+Installation
+
+As root, sudo will not work.
+
+
+echo "*/5 * * * * ${PWD}/mailQWatch.sh" >> /etc/crontab
+
diff --git a/mailQWatch.sh b/mailQWatch.sh
index 565d421..a3848fd 100755
--- a/mailQWatch.sh
+++ b/mailQWatch.sh
@@ -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]")
-SUBJECT="Mail Queue on $HOST is currently $QUEUECOUNT"
-MAILTO="mmckinnon@comprofix.com"
-
+
+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