1829067 Members
2632 Online
109986 Solutions
New Discussion

crontab problem

 
O'lnes
Regular Advisor

crontab problem

Can I run the crontab job fullfit the below requirement:
run on the first day of every month (1st ) and every Monday , but if the 1st is Monday, then the job process one time only (cos i don't wanna have duplicate processing) , is it possible? Thx.
eg.

crontab 1 (single script):
00 09 1 * 1 -- > run on 1st AND Monday only , so not fit my requirement.

Crontab 2 (double script):
00 09 1 * *
00 09 * * 1 --> if the 1st is Monday , then it will run two processes (duplicated)

Andy
8 REPLIES 8
Ian Dennison_1
Honored Contributor

Re: crontab problem

Crntab sequence commands are cumulative,

00 09 1 * 1 jobname.sh

will run the job every Monday AND the first day of the month. This should not run twice on Monday the first!

man page of crontab for perusal,...

If both are specified in an entry, they are cumulative. For example,

0 0 1,15 * 1 command

runs command at midnight on the first and fifteenth of each month, as
well as every Monday.

Share and Enjoy! Ian
Building a dumber user
O'lnes
Regular Advisor

Re: crontab problem

hi Ian Dennison,
thx r reply, but my first statement not fit my requirement cos it only run on the 1st of the month AND Monday ( meet the both conditions) , my requirement is run on 1st day of month OR every Monday (meet anyone of condition is ok), sorry to make you confused. Thx.
Andy
Christian Gebhardt
Honored Contributor

Re: crontab problem

I think there is missunderstood,
as Ian said
00 09 1 * 1 is cumulativ, this script runs
- first day of month
- every monday
- if the first day of month is a monday the script runs only once

Chris
Ian Dennison_1
Honored Contributor

Re: crontab problem

To restate the problem,

You want the job to run every Monday
You want the job to run on the first of every month
When the first of the Month is a Monday, you do not want the job to run twice.

Correct?

Crontab 1 in your original posting should provide for this. Have you tested this crontab entry to see what is happening?

I have tested the following crontab entry just now,...

37 10 5 * 2 /tmp/test.sh

The script has run only once on a Tuesday the 5th of Nov.

39 10 5 * 0 /tmp/test.sh

The script ran once on the 5th of Nov, even though Sunday was configured.

41 10 3 * 2 /tmp/test.sh

The script ran once on a Tueday, even though the 3rd of Nov was configured

Conclusion - Crontab allows multiple parameters to be specified, and will run the command on each and every matching parameter.

Using words like OR and AND is causing confusion I think.

Why not try this at home?

Share and Enjoy! Ian Dennison
Building a dumber user
Elif Gius
Valued Contributor

Re: crontab problem

manpage of crontab:
+++
Note that the specification of days can be made in two fields: monthday and weekday.
If both are specified in an entry, they are cumulative. For example,
0 0 1,15 * 1 command

runs command at midnight on the first and fifteenth of each month, as well as every Monday.
+++
Your crontab entry will do the job :
- every first day in month AND
- every Monday
harry d brown jr
Honored Contributor

Re: crontab problem

Andy,

Just how disrespectful and ungrateful can you be? IN SIX MONTHS? YOU have got to be KIDDING ME!

This member has assigned points to 190 of 474 responses to his/her questions.

Read this:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x376efd3f91d3d5118ff40090279cd0f9,00.html

then find your previous questions here:

http://forums.itrc.hp.com/cm/TopSolutions/1,,CA759973!1!questions,00.html


live free or die
harry
Live Free or Die
Leif Halvarsson_2
Honored Contributor

Re: crontab problem

Hi
It seems as this needs two crontab scripts both doing the same job but the script that runs the first of evry month checks if the day is monday and if this is true exits without doing anything.
This can be done with a test condition using
"date -u +%a"
If this returns "Mon", do nothing.
Darrell Allen
Honored Contributor

Re: crontab problem

One crontab entry is enough. The job will only be run once at any one time even if multiple conditions cause are met at the same time (ie, every Monday and every 1st of the month).

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)