The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-08-2001
Registered User
 

Join Date: Nov 2000
Posts: 5
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?
__________________
Doug
Forum Sponsor
  #2  
Old 10-08-2001
Registered User
 

Join Date: Oct 2001
Location: USA..Georgia
Posts: 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  
Old 10-09-2001
Registered User
 

Join Date: Nov 2000
Posts: 5
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  
Old 10-09-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,613
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".
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0