Scheduling Cron Jobs on Business Days


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scheduling Cron Jobs on Business Days
# 1  
Old 12-30-2010
Scheduling Cron Jobs on Business Days

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?

Code:
00 5 * * 1-5 pr_test.ksh >/dev/null 2>&1

Thank you.

Pramodini

Last edited by Yogesh Sawant; 12-31-2010 at 01:43 PM.. Reason: added code tags
# 2  
Old 12-30-2010
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.

Perhaps this would help..

Last edited by citaylor; 12-30-2010 at 04:33 PM.. Reason: Added link
# 3  
Old 12-30-2010
If your system has cal command.

Code:
$ 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

Code:
date +%d

if they are same, run the script, otherwise, skip it.
# 4  
Old 12-31-2010
@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.

Thank you both for the information.

Pramodini
# 5  
Old 12-31-2010
check if this or this is useful
This User Gave Thanks to Yogesh Sawant For This Post:
# 6  
Old 12-31-2010
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:

Code:
DAY=`date +%d/%m/%Y`
RET_CODE=`grep -c $DAY /home/unxsa/holiday/holiday.date`
exit $RET_CODE

We use this not to run jobs on holidays.

cat /home/unxsa/holiday/holiday.date
Code:
01/01/2011
10/04/2011
13/04/2011
24/05/2010
01/07/2010
02/08/2010
06/09/2010
11/10/2010
11/11/2010
25/12/2010
26/12/2010

# 7  
Old 01-03-2011
@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.

Thanks.

Pramodini

#!/usr/bin/ksh
#Pramodini Rode 12-22-2009 Initial Release
. ~/.profile


CTRL_FL_HOL=team/ctrl/holiday_ctrl.ctrl

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
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. What is on Your Mind?

FX software, business inteligence and analyst jobs

Hi everyone, recently I've been offered a selection procedure for new Barclays development center in Prague. Job role should be something like: Barclays FX Application Management Support Analyst Job in Prague | Glassdoor Could anyone throw me some light into what skill levels are needed, what... (3 Replies)
Discussion started by: smoofy
3 Replies

2. Red Hat

Scheduling cron job

Hi Everybody, I want to run a script at every 5 seconds. I know how to run it every 5 minutes, is there any possibility to run a script at 5 seconds interval. Regards, Mastan (3 Replies)
Discussion started by: mastansaheb
3 Replies

3. Red Hat

Cron entry for every 10 mints on business day business hour

Could you “crontab” it to run every 10 minutes on work days (Mo - Fr) between 08:00 and 18:00 i know to run every 10 mints but can any one guide me how to achieve the above one (2 Replies)
Discussion started by: venikathir
2 Replies

4. Shell Programming and Scripting

Cron Job Scheduling

Hi All, I have a script which is scheduled in the Cron. It runs every 10th and 40th min of an hour.The job has to run every 30min. But, I do not want to have the 00:10 MST run every day.Is it possible to exclude that run from the schedule?Or any other way through which i can run my job every... (4 Replies)
Discussion started by: sparks
4 Replies

5. Shell Programming and Scripting

Scheduling a command to run every 3 days through cron

Hello, I have to schedule a command to run on every 3 days. Whether the below cron entry will work? 0 3 */3 * * command Please help me out and thanks in advance! (6 Replies)
Discussion started by: Arunprasad
6 Replies

6. UNIX for Advanced & Expert Users

Scheduling bi-weekly through cron

Is there a way in AIX to schedule a script to run bi-weekly through cron? I have a script that needs to run every other Wednesday, and this is what I thought I had to enter in the crontab file: 00 08 * * 3/2 /home/user/user.script It didn't like that. It reports a syntax error. I'm almost... (5 Replies)
Discussion started by: LPT
5 Replies

7. HP-UX

cron scheduling?

Hi all, i want a job to run first monday of every of month. (1 Reply)
Discussion started by: megh
1 Replies

8. UNIX for Dummies Questions & Answers

scheduling tasks with cron

hello there, i'm learning about task scheduling with cron and all seems hyper exciting, yeppie. But there is a prob: assume i have a script that needed to be executed at 7am everyday. I could do: vi mycron 00 7 * * * echo hi mother, i wanna be a script daddy. :wq crontab mycron how... (4 Replies)
Discussion started by: alikun
4 Replies
Login or Register to Ask a Question