shell script needed for mail queue notification

Hi shell experts,
I would like to have a shell script running in a redhat server for monitoring the mailqueue status. I have already installed the qmHandle and I am using it to get a status of the mail queue in daily basis. I am executing the qmhandle in the cron.

Now I am planning to execute the qmhandle every hour and the status been mailed to me only, if the amount of mails in the queue meet certain criteria.

e.g. I need the notification been send only if the mails in the remote queue exceeds more than 1000 mails or in the local queue more than 10 mails.

Any help appreciated. Thank you.

The qmhandle will be executed with following command

./qmHandle -s

The out put may be:

Messages in local queue: 3
Messages in remote queue: 583

[ ! -z `./qmhandle -s | awk '($3 == "local" && $NF > 10) || $3 == "remote" && $NF > 1000) {print "mail"}` ] && mail ....

IFS=:
set -f
set -- $( ./qmHandle -s )

localeQ=$(( $2 ))
remoteQ=$(( $4 ))

if [ $localQ -gt 10 ] || [ $remoteQ -gt 1000 ]
then
   {
     printf "Messages in local queue: %d\n" $localQ
     printf "Messages in remote queue: %d\n" $remoteQ
    } | mail someone@example.com
fi

Depending on your system, you may need to use "mailx" instead of "mail".

getting following error:
mailcheck_2.sh: line 6: 530
Messages in remote queue : syntax error in expression (error token is "Messages in remote queue ")

Can you be more specific?

I got it right?

You want to send an email about all emails in queue when that email will be last in queue and by the time it is send reports about emails which where in queue but are already out of queue?

What I need is just a notification email been sent to the admin, when certin criteria met.

"e.g. I need the notification been send only if the mails in the remote queue exceeds more than 1000 mails or in the local queue more than 10 mails."

And in which queue will your email be?

it doesn't matter, since I only need to execute the 'qmHandle -s' which gives the queue output.

If there is queue, and you report about this queue by sending an email, that email will be last in queue.

By the time it will be send it will report about emails in queue which are no longer in queue since they are send prior to your status email.

Good point. never thought about it. anyway do you have any other suggestion to get the admin notified about the mail queue? though the notification mail will be placed in the Remote queue. and it will still work for incomming mails. but most of the cases, the outgoing mails are the problem. not incomming mails. :frowning: