noob. need help to create a script.

Hi All.

im a noob to scripting. could somone help me with a script please.

what i want to do is.

  1. run a cmd in the script - qmqtool -s

this will give me an output similar to this.

Messages in local queue: 790
Messages in remote queue: 306
Messages in todo queue: 23

i then want to check if the message in the local queue is larger than the number of for example 100 ( but id like to be able to change this)

if its larger i want to do.

  1. send email to me@mydomain.com with the output of the qmqtool -s and saying something like this

mail checker script has detected more than 100 emails in the local queue.

Messages in local queue: 790
Messages in remote queue: 306
Messages in todo queue: 23

the script will automatically fix this issue.

  1. service stop spamd
  2. service stop drwebd
  3. service restart xinetd

thats all for now. ill run this script as a cron job every 1 hr.

appreciate any help.

cheers aron.

To get the local queue, pipe the output of 'qmqtool -s' through awk.

lqueue_length=$(qmqtool -s | awk '/local queue/ {print $NF}')
if [ $lqueue_length -gt 100 ]; then
   # send mail using mailx or whatever tool you use
   # fix the problem in the next three lines
   service stop spamd
   service stop drwebd
   service restart xinet
fi