|
Cron 4 times in the script if you want email...
...twice via pipe, if the answer is noooo-ooo! (apologies to Tony Orlando and Dawn, and any readers...)
Sure, it's doable:
$CHECKF="/tmp/runcount" # whatever you want
if [ `date | awk '{print $2 $3}'` = `ls -l $CHECKF | awk '{print $6 $7}'` ] ; then # it ran today
if [ `cat $CHECKF` = "0" ] ; then # it ran successfully
exit # so don't run it again.
fi
<run your script>
if <script ran successfully> ; then echo "0" > $CHECKF ; exit; fi
Now here's what happens if you have a problem:
i=`cat $CHECKF`
i=`expr $i + 1`
if expr $i -gt 3` ; then
echo "Script $0 failed 4 times!" | mailx -s "Failure on `date`" recipient
exit 1
fi
echo $i > $CHECKF
|