1834586 Members
3323 Online
110069 Solutions
New Discussion

cron job

 
M.M. Oee
Contributor

cron job

how can i specify a process to run on every working day after 6.00pm except saturday, sunday and public holidays?
10 REPLIES 10
Mark Grant
Honored Contributor

Re: cron job

01 18 * * 1,2,3,4,5 grep `date` file_of_holidays >> /dev/null || my_command

Cron will do it apart from the public holiday bit. Unfortunately, cron doesn't know about public holidays. One solution, as shown above, would be to create a file containing the dates of public holidays and only run your script if a grep of todays date fails.
Never preceed any demonstration with anything more predictive than "watch this"
Robert-Jan Goossens
Honored Contributor

Re: cron job

00 18 * * 1-5 /usr/local/nsr/bin/rt n n >/dev/null 2>&1

Regards,
Robert-Jan
Sanjay Kumar Suri
Honored Contributor

Re: cron job

00 07 * * 1,2,3,4,5 /Job_name

There is no option to specify the holiday. Except excluding the date in first * postion and mentioning the day of the week in the 2nd last postion.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Sanjay Kumar Suri
Honored Contributor

Re: cron job

Sorry (mistake in hour).

00 18 * * 1,2,3,4,5 /Job_name

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
M.M. Oee
Contributor

Re: cron job

Hi Mark Grant,

can u give me the the format of "file_of_holidays".

Thanks
Mark Grant
Honored Contributor

Re: cron job

Well, that would be up to you really because it's only a file you create yourself, put dates in it and compare to the current system date. It is only a grep.

However, as an example, change the cron entry to this.


01 18 * * 1,2,3,4,5 grep `date +"%d.%m.%y"` file_of_holidays >> /dev/null || my_command

And then put dates in your file_of_holidays like this

16.06.04
02.17.04

etc etc etc. I have assummed a UK date format here because I live in Norway.
Never preceed any demonstration with anything more predictive than "watch this"
Muthukumar_5
Honored Contributor

Re: cron job

Hai.

crontab don't know about the holiday's. Create a file to know the holiday with the format mm/dd/yyyy as

#--- /var/tmp/holiday ---
10/15/04
22/08/04

Set the crontab settings as
# mins hours m-day month weekday command
0 18 * * 1-5 grep `date "+%x"` /var/tmp/holiday >/dev/null | command

Regards,
Muthukumar
Easy to suggest when don't know about the problem!
Sanjay Kumar Suri
Honored Contributor

Re: cron job

Excluding the holiday in "Day of the Week" is a task.

To include following format should work:

grep `date "+%x"` holiday_list | date "+%Ow"

assuming the date format in holiday_list as 06/16/04.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Steve Post
Trusted Contributor

Re: cron job

I got this from somewhere on the forums.

If you want to put a specific schedule into the program itself instead in the crontab file?

Well here's the code snippet......
# Have a $x1_listofdates in this program that gives a schedule.
# 2. Run the cronjob every day from 1st to 10th of the month.
# 3. Have the job exit out unless the day matches the schedule.
#
# note: typeset -i tells unix the value is an integer, not octal binary.
#------------------------------------------------------------------------------
typeset -i x1_day_of_month=`date +"%d"`
x1_month_of_year=`date +"%b"`
typeset -i x1_year=`date +"%Y"`

x1_datestring=`printf "%02d%s%4d\n" $x1_day_of_month $x1_month_of_year $x1_year`

#---SCHEDULE---o---SCHEDULE---o
x1_listofdates="
02Jun2004
02Jul2004
03Aug2004
02Dec2004
"

x1_FLAGRUN=0
echo "Run the job today?"
for x1_D in $x1_listofdates
do
echo " today is $x1_datestring look at $x1_D from the list. "
if [ "$x1_D" = "$x1_datestring" ] ; then
x1_FLAGRUN=1
fi
done
if [ $x1_FLAGRUN != 1 ] ; then
echo "do not run job today"
exit
else
echo "Run job today"
fi

In this code, I have the job only run on selected days. But you could easily reverse it. Note the "typeset -i" when I got to day "08", the code though it was octal, and wanted to be "10". The -i lets it know it is an integer, not octal.

Steve
Steve Post
Trusted Contributor

Re: cron job

uh hey?
Did you ever think that maybe you could kinda assign points to tell folks if the help is useful or not? I see you assigned points to 0 our of your 39 questions.

None of the answers were useful?