The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 9 01-09-2009 12:52 PM
CRONTAB: Every second Tuesday of the month Cameron UNIX for Dummies Questions & Answers 2 06-02-2008 10:50 PM
Extract Monday from given date itsme_maverick UNIX for Advanced & Expert Users 2 05-29-2008 05: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 02:59 PM
CAn any1 help me pls...urgent need to pass up this monday yeah016 UNIX for Dummies Questions & Answers 1 07-20-2006 10:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-08-2001
molonede molonede is offline
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?
  #2 (permalink)  
Old 10-08-2001
punter5 punter5 is offline
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 (permalink)  
Old 10-09-2001
molonede molonede is offline
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.


Last edited by molonede; 10-09-2001 at 09:55 AM..
  #4 (permalink)  
Old 10-09-2001
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,123
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".
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0