![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| crontab entry to run every last day of the month | tads98 | Shell Programming and Scripting | 7 | 09-09-2008 10:23 PM |
| CRONTAB: Every second Tuesday of the month | Cameron | UNIX for Dummies Questions & Answers | 2 | 06-02-2008 06:50 PM |
| Extract Monday from given date | itsme_maverick | UNIX for Advanced & Expert Users | 2 | 05-29-2008 01:15 AM |
| I wanted to get the date of the first monday of a month. | Sheethal | UNIX for Dummies Questions & Answers | 6 | 09-15-2007 10:59 AM |
| CAn any1 help me pls...urgent need to pass up this monday | yeah016 | UNIX for Dummies Questions & Answers | 1 | 07-20-2006 06:33 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Is there a way to setup a cronjob that will only run on the first monday of the month?
__________________
Doug |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
|||
|
|||
|
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.
__________________
Doug Last edited by molonede; 10-09-2001 at 05:55 AM. |
|
#4
|
||||
|
||||
|
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 |
||||
| Google The UNIX and Linux Forums |