Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identify first Monday of the month

Status
Not open for further replies.

jawon

Programmer
Feb 6, 2003
31
0
0
US
I'd like a script to complete only if it is the first Monday of the month. Can this be done in the crontab file or do I have to do an if/then within the script? If the latter, how?
 
With crontab you can specify thee day of week for the execution of a command, but not in th form of 'the first monday of the month'.

A solution :

In your crontab file specify the excution of you script on every Monday.

In your script add :

[ `date +%d` -gt 7 ] && exit

Jean Pierre.
 
You can also put all the 'logic' in the crontab file without modification in your script :

hour(s) minute(s) * * 1 [ `date +%d` -le 7 ] && your_script

Jean Pierre.
 
It doesn't have to be that complicated. This will run a job at noon on only the first Monday of every month...
Code:
0 12 1-7 * 1 first_monday_script
Hope this helps.

 
No ! crontab will run the job the first seven days of the month AND every Monday

Jean Pierre.
 
I must agree with Jean-Pierre.
From my man page:
Note that the specification of days may be made by two fields
(day of the month and day of the week). If both are specified as
a list of elements, both are adhered to. For example, 0 0 1,15 *
1 would run a command on the first and fifteenth of each month,
as well as on every Monday. To specify days by only one field,
the other field should be set to `` * '' (for example, 0 0 * * 1
would run a command only on Mondays).

Hope This Help
PH.
 
D'oh!

Yeah, you're right! My bad!

BTW, when are they going to fix that? [thumbsup]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top