Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 10-23-2005
mschwage mschwage is offline
Registered User
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 102
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