Hello, is it possible to schedule cron jobs using business days instead of calendar days? I need to run several jobs on first and third business days of the month. I currently have this cron-tab entry which runs every week day at 5 AM. I need to schedule the same job on the 3rd Business day of the month. Any ideas to make this happen?
I doubt cron will be versatile enough to schedule like this - even linux versions, but it could quite easily just call the script every day, and then you can provide the logic in the script to only run the required functionality if it meets the working day requirement.
$ cal |awk 'NR>2 {print substr($0,4,14)}' |tr "\n" " " |awk '{printf "First business day is %s \nThird business day is %s \n", $1,$3}'
First business day is 1
Third business day is 3
Add above code in your script. compare with
date +%d
if they are same, run the script, otherwise, skip it.
@rdcwayx, I do not see �cal� command. @citaylor, you are right, UNIX is not that versatile. I can handle the business days logic via K-Shell script, I was trying to avoid that.
As others have pointed out, I would run a script everyday. In that script check to see if it is the day you want the script to run, if not exit.
You're only talking about 24 days a year. Create a file with the days you want the script to run. Then grep the file using today's date. If today's date is in the file, continue the script. (If not exit). It could be as simple as:
@purdym , I currently have this for not running the jobs on holidays and I plan to have a similar structure for business days as well.
Before the script below runs, I have a job that checks our Corporate Holidays calendar and creates a control file using holiday_ctrl.ctrl using SAS.
if [[ -e $CTRL_FL_HOL ]]
then
print "Pramodini today is a holiday"
print "Exiting Program"
exit
else
print "Pramodini today is a working day"
print "Execute Program"
fi
Further to "purdym".
The whole year can be scheduled positively with 12 lines in crontab (each of which fires on two days-of-the-month within each the calendar month number). With this approach you must only specify day-of-month and not mention day-of-week or the cron will fire incorrectly.
Btw. The method using the unix "cal" command is awesome. Depending on the requirement it may go wrong if Bank Holidays are not deemed Business Days. Otherwise it seems perfect.