#!/bin/bash
# get server hostname
hostname=`cat /etc/hostname`
current_mailq=`postqueue -p | tail -n 1 | cut -d' ' -f5`
yourEmail="YOUR_EMAIL_HERE"
if [ "$current_mailq" -gt "100" ]
then
echo "Mail queue problem - there is currently $current_mailq mails in queue. Please check it out." > check_email_queue_outgoing.txt
mail -s "$hostname - mail queue alert - there are $current_mailq emails in queue" "$yourEmail" < check_email_queue_outgoing.txt
else
echo "Mail queue is fine - there is currently $current_mailq mails in queue. Please check it out."
echo "Do nothing, situation is fine."
fi