Register a domain and help support LQ
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 10-18-2012, 08:28 AM   #1
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:
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, 09:13 AM   #2
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 which is a web page that builds the line for your crontab.
- Raj
1 members found this post helpful.
Old 10-18-2012, 05:07 PM   #3
Senior Member
Registered: Apr 2010
Location: USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 1,568

Rep: Reputation: 520Reputation: 520Reputation: 520Reputation: 520Reputation: 520Reputation: 520

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-18-2012, 11:14 PM   #4
LQ Newbie
Registered: Oct 2012
Posts: 26

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

Rep: Reputation: Disabled
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, 08:24 AM   #6
Senior Member
Registered: Aug 2009
Distribution: CentOS
Posts: 2,875

Rep: Reputation: 1235Reputation: 1235Reputation: 1235Reputation: 1235Reputation: 1235Reputation: 1235Reputation: 1235Reputation: 1235Reputation: 1235
Originally Posted by arun5002 View Post
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.
30 23 * * 5 [ `date '+\%e'` -le 7 ] && /path/to/script
1 members found this post helpful.


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 04:03 PM
Configure cron entry to run every other Friday? MarkEHansen Linux - General 1 10-14-2010 03: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 06:33 PM
Cronjob for every second Saturday of the month kinetik General 3 02-26-2009 04:56 AM
Cron Job to run on 2nd and 4th Friday of each month rust8y Linux - General 1 06-25-2007 09:07 PM

All times are GMT -5. The time now is 09:37 AM.

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