Schedule a script to run at 10am from mon to fri

Hi,

I need to write a shell script which will run i background and will execute other script only on Mon to Fri 10 AM but not on Sat and Sun.

I am able to set it to run on every day at 10AM but how to make it to run only on Mon to Fri

Thanks,
Firestar.

the entry should be like this..

00 10 * * 1-5 your script

Sorry to confuse you....

i dont have access to crontab i need to write in shell scriptt..

date +%u returns the number of the day in the current week. (1 is monday, 2 is tuesday, ...)
You can write something like :

if [ $(date +%u) -lt 6 ]; then
   echo 'command to execute'
fi

to get the job done :slight_smile:

1 Like

Thank you.
For Sat its 6
and Sun its 7
is dat correct..

It is correct. See "man date".

As you noticed, Sunday is day zero in cron ... but day seven in "date +%u".
Just for interest "date +%w" gives the Weekday numbered the same way as cron.

Ps. We need to know whether "the script" does anything other than sit there idling and fire off another script at 10:00 on weekdays. How accurate does 10:00 need to be? Would up to 59 seconds either way matter?

Can you post your incomplete script?

1 Like

Downside is if the system is re-booted, put in single user mode or your script dies the job won't run. Perhaps you could add something to your .profile so when you login it checks the script is still running and fires it off again.

Another thought, do you have access to run at jobs?

Thank you Guys,

I made it run

here is the script.

while true
do
CURRHOUR=`date "+%H"`
CURRDATE=`date "+%u"`

if [ $CURRDATE -lt 6 ]; then
if [ $CURRHOUR -eq 10]; then

       // program
        sleep 3600
else
        sleep 30
fi
fi
done
#to run : $ nohup ./daily_run.sh &