LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 10-18-2012, 09:28 AM   #1
a9b8c2
LQ Newbie
 
Registered: Dec 2010
Posts: 4

Rep: Reputation: 0
cronjob to run a command at first friday of each month


hi there
i use 3 13 1-7 * 5 in cronjob to run my command at first friday of each month,
but i see that the command run on days 1 - 7 and also all fri day!
then i found below note in wikipedia:
Quote:
if both "day of month" and "day of week" are restricted (not "*"), then either the "day of month" field (3) or the "day of week" field (5) must match the current day.
so, how i can solve the problem?
 
Old 10-18-2012, 10:13 AM   #2
Rupadhya
Member
 
Registered: Sep 2012
Location: Hoffman Estates, IL
Distribution: Fedora 20
Posts: 167

Rep: Reputation: Disabled
I am not sure how to fix this, because I am a bit confused on complex crontab rules. You might check out http://www.corntab.com which is a web page that builds the line for your crontab.
- Raj
 
1 members found this post helpful.
Old 10-18-2012, 06:07 PM   #3
wpeckham
Member
 
Registered: Apr 2010
Location: USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix
Posts: 832

Rep: Reputation: 181Reputation: 181
Easy

Schedule your job to run a script every Friday. Have that script check the DOM (`date +"%d"`) and see if it is less that 08. If not, exit, otherwise run your process.
 
Old 10-19-2012, 12:14 AM   #4
venkatesh51
LQ Newbie
 
Registered: Oct 2012
Posts: 26

Rep: Reputation: Disabled
a9b8c2
crontab order is
minute hours dayofmonth mont dayofweek
30 3 1-7 1-12 5
 
Old 10-19-2012, 06:54 AM   #5
arun5002
Member
 
Registered: Aug 2011
Location: Chennai,India
Distribution: Redhat,Centos,Ubuntu,Dedian
Posts: 549
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
30 23 * * 5 [ `date '+%e'` -le 7 ] && /path/to/script
MIN min field to be 0-59
HOUR Hour field 0 to 23
DOM Day of Month 1-31
MON Month field 1-12
DOW Day Of Week 0-6
CMD Command Any command to be executed.
 
1 members found this post helpful.
Old 10-19-2012, 09:24 AM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,615

Rep: Reputation: 675Reputation: 675Reputation: 675Reputation: 675Reputation: 675Reputation: 675
Quote:
Originally Posted by arun5002 View Post
Code:
30 23 * * 5 [ `date '+%e'` -le 7 ] && /path/to/script
Please don't use [QUOTE] tags for code. That makes it hard to include your code in a reply. Use [CODE] ... [/CODE] tags instead.

You're close, but the "%" sign is special to cron and needs to be escaped.
Code:
30 23 * * 5 [ `date '+\%e'` -le 7 ] && /path/to/script
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
dcron - run script last friday of month cotton213 Linux - Software 7 06-25-2012 05:03 PM
Configure cron entry to run every other Friday? MarkEHansen Linux - General 1 10-14-2010 04:13 PM
how do i get a cronjob to run every two hours in AIX: 00 */2 * * * command no work boyd98 AIX 1 10-19-2009 07:33 PM
Cronjob for every second Saturday of the month kinetik General 3 02-26-2009 05:56 AM
Cron Job to run on 2nd and 4th Friday of each month rust8y Linux - General 1 06-25-2007 10:07 PM


All times are GMT -5. The time now is 10:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration