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.
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
---------- 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)...
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