I have a script that runs every 15 minutes in cron that builds a web page.
It runs at 15, 28, 45 and 58 minutes past the hour. (pretty much evry 15 mins).
Every 2 hours from 6:28 to 18:28 it sends out emails if it finds errors. I do not want it sending email every single time it runs, every 15 mins.
if $thour = "06:28" +2 hours up until "22:28" then ...... send the email
If I want to extend it beyond 18:28 as in my pretend statment above .. I'd like to be able to just change a range rather than keep adding more confitions in the if statement.
Whats more is that the script does a bunch of things and this timeline for sending emails is used a few times in the script like this:
build web page one
if errors are found send email to ABC with subject XYZ at times in this range
build web page two
if errors are found send email to DEF with subject UVW at times in this range
I am using crontab. The cron runs the script every 15 minutes.
I do not want the email every 15 minutes. I want the script to recognize that it's 6:28, time to send an email if there is one to send.
to use the crontab specifically for the email I'd have to have 2 versions of the script in crontab.
by default, the email will be sent every 2 hours starting 0628 and ending 1828 unless the start and end times are changed ... need to set 3 arguments if needing to extend the end hour and 4 arguments if needing to change the minute with Y as the first argument ... $1 should be Y to send, N to not send, G to send immediately ... if G is selected, no other arguments are required ...
#! /bin/ksh
SEND=$1
SEND=${SEND:=Y}
START=$2
START=${START:=6}
END=$3
END=${END:=18}
MIN=$4
MIN=${END:=28}
MYHR=$(date +%H)
MYMIN=$(date +%M)
if [ $MYHR -ge $START -a $MYHR -le $END -a $MYMIN -eq $MIN ]
then
ZERO=$(expr $MYHR % 2)
if [ $ZERO = 0 ]
then
OK=Y
else
OK=N
fi
fi
case $SEND in
Y) if [ $OK = "Y" ]
then
mail_report
fi ;;
G) mail_report ;;
esac
this could be better but i don't have a sun box nor the time to test ... test properly before putting anything into production mode ...