#!/bin/sh
#display mailq to the screen
mailq | tail -1 | cut -d ' ' -f 3
#check mail queue size and if it is larger than 300, send alert message.
if [ `mailq | tail -1 | cut -d " " -f 3` -ge "300" ]; then
echo "Mailq on sendmail is over 3900 on NS5 as of $(date)" |
mail -s "Alert: Mailq for NS5! is over 300" EMAIL@EXAMPLE.com
fi