[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 672
  • Last Modified:

Shell script for a mail queue notification

I have a sendmail  server. I need a shell script to notify the admin via mail if more than 10 mails in mail queue.
0
rajasekarramasamy
Asked:
rajasekarramasamy
  • 3
  • 2
1 Solution
 
omarfaridCommented:
can you show the output of command

mailq -v
0
 
rajasekarramasamyAuthor Commented:
Output:

mailq -v
/var/spool/mqueue is empty
           Total requests: 0
0
 
omarfaridCommented:
you need to give me an output where it shows some messages are in the queue :)
0
 
rajasekarramasamyAuthor Commented:
     /var/spool/mqueue (1 request)
----Q-ID---- --Size-- -Priority- ---Q-Time--- ---------Sender/Recipient--------
n3MD4pZ13060      235      30478 Apr 22 18:34 <thana@xyz.com>
                 (Deferred)
                                    <chn2009@yahoo.com.com>
0
 
omarfaridCommented:
you may try:

q=`mailq -v | grep request`
c=`echo $q | wc -w`
if [ $c -gt 0 ]
then
      n=`echo $q | sed 's/(//' | awk '{ print $1 }'
      mailx -s "you have $n message(s) in queue" yourname@yourdomain.com
fi
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now