Crontab First Monday of Month only


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Crontab First Monday of Month only
# 1  
Old 10-08-2001
Question Crontab First Monday of Month only

Is there a way to setup a cronjob that will only run on the first monday of the month?
# 2  
Old 10-08-2001
I must first say that I am fairly new to Unix and know very little about cronjobs, but your question intrigued me. My first question to you would be what OS are you using? The majority of my experience is with Solaris 7, so I will be speaking in terms of that.

I read the man pages on crontab and found the six fields that make up the crontab entry format:

1. Minute (0-59)
2. Hour (0-23)
3. Day of the Month (1-31)
4. Month of the Year (1-12)
5. Day of the Week (0-6) 0 being Sunday.
6. the executable string

So say you want to run your cronjob at midnight on the first Monday of ever month, it appears that the first 5 fields should look something like this:

0 0 1-7 * 1

My thinking:

0 - Is the first minute of that day
0 - Is the first hour of that day
1-7 - The first Monday has to fall within the first seven days of the month.
* - Every month
1 - Only on Mondays

Unless I am misreading the man pages, it seems like this should work. I am going to attempt to set up a cronjob and test it.

Best regards.
# 3  
Old 10-09-2001
Sorry that I left the time out, but midnight will work fine.

0 0 1-7 * 1 command

this should execute the 'command' at Midnight on all Mondays AND first 7 days of a month.

I just need the first Monday.


Last edited by molonede; 10-09-2001 at 09:55 AM..
# 4  
Old 10-09-2001
You're right, molonede, "0 0 1-7 * 1 somecommand" will run command on the first 7 days of each month and on every Monday of each month. We all wish it worked the way punter5, but it doesn't. This means that you can't get what you via crontab alone.

This usual solution is something like, first write a wrapper script that will run somecommand only if the day of the month is 7 or less:
Code:
#! /usr/bin/ksh
day=$(date +%d)
if ((day <= 7)) ; then
   exec somecommand
fi
exit 1

Then run the wrapper every Monday: "0 0 * * 1 wrapper".
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to find second and fourth Monday of the month?

Hi, I have came across the scenario where, we have to run the script on second and fourth Monday of each month. I have tried to search man page of date and also forum for it but, could not get any answer to this. Can you please advise how can we get second and fourth Monday of the month? ... (18 Replies)
Discussion started by: Prathmesh
18 Replies

2. UNIX for Dummies Questions & Answers

How to Set crontab for 4th and 25th of every month?

Hello, I wanted to set Crontab for 4th and 25th of every month at 5:00 PM. Script should take previous month and current year as command line arguement like... /home/test1.sh -f ABCD 03 2014 so above script will run on 4th and 25th April 2014 but argument should be like previous month... (11 Replies)
Discussion started by: ajju
11 Replies

3. Shell Programming and Scripting

crontab: setup cronjob to run first wednesday of every month

Hi, How to setup cronjob to run first wednesday of every month. Is there a way? Thanks.. (9 Replies)
Discussion started by: Anjan1
9 Replies

4. Solaris

crontab entry to run a script on 1st of every month.

What should be the crontab entry in solaris to run a script on 1st of every month? Is this correct? 00 02 1 * * <script to be executed> (5 Replies)
Discussion started by: deepaksahni0109
5 Replies

5. UNIX for Advanced & Expert Users

Crontab For First Monday Of Every Month!!

Hi, Could any one please let me know the crontab entry for scheduling a job for every first monday of the month? Thank You in advance, Sue (2 Replies)
Discussion started by: pyaranoid
2 Replies

6. Shell Programming and Scripting

crontab entry to run every last day of the month

i've created a script which should run every last day of the month. what would be the exact crontab entry for this? thanks! (9 Replies)
Discussion started by: tads98
9 Replies

7. UNIX for Dummies Questions & Answers

cron script -run every 2nd day of month except Monday

I know I can't schedule this in cron and would have to write a wrapper around my script and schedule it in cron ....but not sure how do to this? How do I exclude Monday if the 2nd day of the month falls on a Monday? Thanks. I tried this: 0 0 2 * 0,2-6 command And I know this doesnt... (2 Replies)
Discussion started by: newtou
2 Replies

8. UNIX for Dummies Questions & Answers

crontab schedule - first thursday of every month

Instead of the first five fields, one of eight special strings may appear: string meaning ------ ------- @reboot Run once, at startup. @yearly Run once a year, "0 0 1 1 *". @annually (same as @yearly) @monthly Run once a month, "0 0 1 * *". @weekly Run once... (2 Replies)
Discussion started by: paulds
2 Replies

9. UNIX for Dummies Questions & Answers

CRONTAB: Every second Tuesday of the month

Morning everyone. You'll need to excuse me for I'm running a little empty this morning. Need to execute a job every second Tuesday of the month. Am I correct in my understanding that this isn't possible directly from crontab & hence I'll need to script. Does anyone have any similar solutions ?... (2 Replies)
Discussion started by: Cameron
2 Replies

10. UNIX for Dummies Questions & Answers

I wanted to get the date of the first monday of a month.

Hi, I need to display the date of the first monday of a month. Can any one please help me on this. Thanks in advance. (6 Replies)
Discussion started by: Sheethal
6 Replies
Login or Register to Ask a Question