1862927 Members
1955 Online
110446 Solutions
New Discussion

about the crontab

 
SOLVED
Go to solution
hangyu
Regular Advisor

about the crontab

I want to disable the crontab job run at 1-9th , if I set as below , is it mean the batch will run at every monday to friday EXCEPT 1-9th ? thx

0 9 10-31 * 1-5
9 REPLIES 9
Nguyen Anh Tien
Honored Contributor

Re: about the crontab

0 9 10-31 * 1-5 command or script
IT means your command will run at 9:00 from 10th to 32st each month and from monday to friday. If 1st ->9th falls to monday and friday you sript still execute.. -> BECAREFUL.I HAVE ONCE CASE LIKE THIS.
HTH
HP is simple
Stephanie Nicholls
Frequent Advisor

Re: about the crontab

The effects of month day and weekday are cumulative. So the job will run every monday to friday as well as every day from the 10th of the month to the 31st, at 9am.

As far as I know with cron there is nothing to specify what you are after, which is every monday to friday. I would set it up like
0 9 10-31 * * <script_name>

and then put a quick day of the week check in the beginning of the script to exit out if its not a weekday.


HTH

Steph
hangyu
Regular Advisor

Re: about the crontab

If I want to run from monday to friday but except 1-9th , can suggest how to set ? thx
Bill Hassell
Honored Contributor
Solution

Re: about the crontab

It cannot be done with cron. You have to modify your job to test for the current day of the month and if it is 1-9, then exit.


Bill Hassell, sysadmin
Raj D.
Honored Contributor

Re: about the crontab


0 9 10-31 * 1-5 command will run at 9:00 from 10th to 31st each month and from monday to friday.
Not sure if it will skip 1 to 9th , as 1-5( that is Monday - to Friday) specified. Seems you need to control at the job level to set this.

Cheers ,
Raj.

" If u think u can , If u think u cannot , - You are always Right . "
Devesh Pant_1
Esteemed Contributor

Re: about the crontab

hangyu,
here is a solution. Leave the crontab with
0 9 10-31 * 1-5 scriptname

In the script add the check

#!/bin/ksh

curdate=`/usr/bin/date | awk '{ print $3 }'`

if [ "$curdate" > "9" ] ; then

batchjob

fi

this will run the batch job Mon through Friday only if the date is greater than 9

Hope this will resolve your issue

thanks
DP
Nguyen Anh Tien
Honored Contributor

Re: about the crontab

Pant's solution is good, PLS give point for us
HP is simple
hangyu
Regular Advisor

Re: about the crontab

thx Devesh Pant ,

I tried your method , it work perfect , but I am wonder the crontab job condition ( minute ,time , date , month , year ) are not "AND" relation , it seems the job not to be run only when fullfit all conditions , they seems are "OR" relation. If not use Pant' method , is it possible to meet my requirement by just use crontab function ? thx
Leif Halvarsson_2
Honored Contributor

Re: about the crontab

Hi,
Cron is a rather simple scheduling tool, as pointed out in previous posts, it is not always possible (as in your case) to perform scheduling without using additional tests in the script.