Web Hosting Talk







View Full Version : Help needed on shell script to send mailqueue status.


NightMan
02-12-2007, 06:10 AM
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

NightMan
02-13-2007, 08:52 PM
...no one???

Engelmacher
02-13-2007, 09:53 PM
Are you asking someone to write this for you or are you looking for suggestions as to how it could be done?

tiamak
02-13-2007, 10:12 PM
#!/bin/bash
qlimit=1000;
notifyemail=your@email.here;

# i dont have qmHandle so i tested following command:
# count=`echo "Messages in remote queue: 1583" | grep "remote queue" | awk -F ":" '{print $2}' | sed 's/ //g'`;

# and i guess u should use ...
count=`./qmHandle -s | grep "remote queue" | awk -F ":" '{print $2}' | sed 's/ //g'`;
# or something like that :D


if [ $count -gt $qlimit ]; then
echo $notifyemail;

# if u get send-mail: invalid option -- s error :D
# you can try
# mail -s 'Mailqueue is full' $notifyemail <<EOF ... blah blah ... :D

mail $notifyemail -s 'Mailqueue is full' <<EOF
Hello Master :)

We have $count in mailqueue
EOF
fi


oops ive just read u want it also to check local mqueue :D
this script should work for your remote queue but im pretty sure u will know how to rewrite it to check local mqueue aswell ;)

anyway
this should give u some idea how to make ur own script
have fun :D

NightMan
02-13-2007, 10:24 PM
Thank you. I will take a look and adjust it for my needs.

NightMan
03-03-2007, 05:41 AM
got it modified and working great. thank you!