Cron scheduler issue

I am trying to schedule a script in Linux to between 8th and the 31st of each month on Sundays @ 6:50 only and i scheduled it as follows:

50 6 8-31 * 0 ksh /home/cpac/SPID_Files/GetFiles.ksh 

Which did it run on the 8th on Saturday instead of only Sundays !!!

That isn't the way cron works. The crontab entry:

50 6 8-31 * 0 ksh /home/cpac/SPID_Files/GetFiles.ksh

specfies that the command ksh /home/cpac/SPID_Files/GetFiles.ksh is to be run at 06:50 on every day that is a Sunday and on every day with a day of month that is is from 8 through 31 inclusive. So, in November 2014, it would run on the 2nd and the 8th through the 30th.

1 Like

Don's very clear message is that both day of the week and day of the month are both going to act independently to run the job at 6:50 AM

You have to check either the day of the week or the day of the month outside of the * * * * section of the crontab line, and drop that check in the section. Both together do not fly the way you want.

try:
set the Sunday ( 0 ) to a * then add logic to see if it is Sunday:

50 6 8-31 * *  [ `date +%w` -eq 0 ] && ksh /home/cpac/SPID_Files/GetFiles.ksh  
1 Like

I also figured it out as follows:
50 6 8-31 * * [ "$(date '+\%a')" == "Sun" ] && /home/cpac/scripts/CommandLine/GetFiles.ksh

Thank you Jim. Your suggestion is great too.