Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduling a job to run at specific time

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
US
How do I create a cron entry that will run a job on the
3rd workday of the month and -3rd workday of the month?

Any help will be greatly appreciated
 
Here's an idea, which will probably be blasted by the smarter folks, but should work:
Wrap your job inside a script like this:

day=`date +%d`
if [ "$day" = "1" ]
then
> /tmp/runlog
fi
run_num=`wc /tmp/runlog|awk '{ print $1 '}`
if [ "$run_num" = "2" ]
then
>/tmp/runlog
{do your script or process here}
else
echo "Not Today" >>/tmp/runlog
fi

Then, create a CRON entry which only runs Monday-Friday and then only on the first 5 days:
10 11 1-5 * 1-5 /usr/local/bin/myscript

This doesn't account for Holidays, which would vary by locale anyway.

It's a starting point...


 
A "wrapper" script or putting a test at the start of the actual script were suggested as solutions last time this issue was raised.

Please check the CRON entry, perhaps with a test script, because I think that the following:
10 11 1-5 * 1-5 /usr/local/bin/myscript
will run at 11:10hrs on the 1st to 5th of every month and every Monday to Friday. (not 1st to 5th as long as they are weekdays)

I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top