Stop sending mail after certain number of mail

Hi guys...

I am busy writing a script to notify me via an mail if my application is down. I have done that.

Now I want this script to stop sending mails after five mails were sent but the script should keep on checking the application.

When the application is up again that count should be cleared.

Please help!!!!!!!!!!!!!!!!!!!!

Write that count into a temporary file with a redirection of an echo for example and check it every time the script is started and noticed an error. When an error is detected, increment it's content by 1. When it's content reaches 5, continue but do not enter the branch to send a mail anymore.
When the application is up again, let the script echo a 0 or 1 into that temporary counter file.

Thanks for the reply...

I don't do scripting most of the time...

Can you please show me some hint in terms of commands...

Thanks a lot for the help!!!!!!!!

Assuming ksh, but probably very similar in other shells:-

if <whatever your condition is>
then
   ((i=`cat statusfile`+1))
   echo $i > statusfile
   if [ $i -le 5 ]
   then
       sendmail commands here
   fi
else
   echo 0 > statusfile     # Make sure there is a space after the zero
fi

Does that help?

Robin

1 Like

Thanks a million times...

This will help a lot...

---------- Post updated at 04:06 PM ---------- Previous update was at 02:46 PM ----------

One quick question. I want this script to send mail to different group of people. That is if it is during business hours (i.e. 8H00 am and 18H00 pm to certain group and after hours to another group)...

How can I achieve this?

Phuti,

Sorry for the delay, I have been away.

A simple test on the system clock should help. You could insert the following:-

if <whatever your condition is>
then
   ((i=`cat statusfile`+1))
   echo $i > statusfile
   if [ $i -le 5 ]
   then
       if [ `date +%H` -ge 8 -a `date +%H` -lt 18 ]
       then
          sendtolist="aaa@abc.com; bbb@abc.com; ccc@abc.com"
       else
          sendtolist="xxx@abc.com; yyy@abc.com; zzz@abc.com"
       fi
       sendmail commands here using $sendtolist
   fi
else
   echo 0 > statusfile     # Make sure there is a space after the zero
fi

I hope that this helps you a bit more.

Robin
Blackburn/Liverpool
UK