Scheduling Cron Jobs on Business Days


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scheduling Cron Jobs on Business Days
# 8  
Old 01-03-2011
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.
# 9  
Old 01-03-2011
Quote:
Originally Posted by methyl
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.
Thanks.

When I gave the solution, the poster didn't mention that we need exclude public holiday.

@ Pramodini Rode
Anyway if cal is not available, maybe there is similar command in your system, I give you the sample output of cal

Code:
$ cal
   January 2011
 S  M Tu  W Th  F  S
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

$ cal 8 2011
   August 2011
 S  M Tu  W Th  F  S
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

So following my solution, we can do some adjusts to find out any business days.

Code:
cat /home/unxsa/holiday/holiday.date 

01/01/2011
10/04/2011
13/04/2011
24/05/2011
01/07/2011
02/08/2011
06/09/2011
11/10/2011
11/11/2011
25/12/2011
26/12/2011

you can run the script by: (only work in ksh, don't know why not work in bash)

for example, you need know the third business day in current month

Code:
./find_business_day 3

the 10th business day in August 2011

Code:
./find_business_day 10 8 2011

$ cat find_business_day

Code:
#! /usr/bin/ksh

Day=$(date +%d)
Month=$(date +%m)
Year=$( date +%Y)
HOLIDAY=/home/unxsa/holiday/holiday.date 
AWK=nawk

usage () {
  echo "Holiday date file at $HOLIDAY"
  echo "Usage: $0 Day [ Month Year ] "
  echo "example: "
  echo "get the 5th business day in current month"
  echo "$0 5 "
  echo "get the 10th bueinsee day on May 2010"
  echo "$0 10 5 2010"
}

if [[ $1 == "" ]]; then
  usage
  exit
else
  Bday=$1
fi

if [[ $3 == "" ]]; then
  CAL="/usr/bin/cal"
else
  Month=$2
  Year=$3
  CAL="/usr/bin/cal $Month $Year"
fi

Blist=$( $CAL |$AWK 'NR>2 {print substr($0,4,14)}' |tr "\n" " ")
$AWK -F \/ -v m=$Month -v y=$Year '$2==m&& $3==y {sub(/^0/,"",$1);print $1}' $HOLIDAY |while read line
do
  Blist=$(echo $Blist |$AWK -v d=$line '{for (i=1;i<=NF;i++) $i=($i==d)?"":$i}1' )
done

echo $Blist |$AWK -v d=$Bday '{print $d}'

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