LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-06-2016, 01:47 PM   #1
paperbagperson
LQ Newbie
 
Registered: Mar 2016
Posts: 10

Rep: Reputation: Disabled
Best Way to Write Crontab


I want to run a cron every 5 minutes except for once at 3:05 am. Is there a better way to write it than:

Code:
*/5 0-2,4-23 * * * /var/tmp/
0,10-55/5 3 * * * /var/tmp/
Is this even written correctly?

Last edited by paperbagperson; 05-06-2016 at 01:51 PM.
 
Old 05-06-2016, 01:51 PM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
Personally I would just schedule it to run every 5 minutes in cron to make it more clear, and in the script have it check the current time. If it's 3:05 then exit, otherwise continue.
 
1 members found this post helpful.
Old 05-06-2016, 04:11 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
Quote:
Originally Posted by paperbagperson View Post
I want to run a cron every 5 minutes except for once at 3:05 am. Is there a better way to write it than:

Code:
*/5 0-2,4-23 * * * /var/tmp/
0,10-55/5 3 * * * /var/tmp/
Is this even written correctly?
The first seems fine, I have doubt for the second (eg does cron apply /5 for the whole expression or just for the 55 value... that does not make much sense anyway)

Edit:
After reading man crontab and from this example
Code:
# run every two hours between 11 pm and 7 am, and again at 8 am
              0 23-7/2,8 * * * date
It seems your second crontab line should work

Last edited by keefaz; 05-06-2016 at 04:21 PM.
 
Old 05-06-2016, 04:25 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,048

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
It looks ok to me. The /5 applies to the entire range (10-55).

http://www.pantz.org/software/cron/croninfo.html
 
Old 05-06-2016, 04:27 PM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
I agree with thesnow though, if a script shouldn't run at 3:05, I would check this condition in the script itself
 
Old 05-12-2016, 12:13 PM   #6
paperbagperson
LQ Newbie
 
Registered: Mar 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by thesnow View Post
Personally I would just schedule it to run every 5 minutes in cron to make it more clear, and in the script have it check the current time. If it's 3:05 then exit, otherwise continue.
This is what I ended up doing, along with making the time a value passed through the crontab so it's easier to configure the time! Thanks

Code:
*/5 * * * * /var/tmp/ RESTART_TIME=

Last edited by paperbagperson; 05-12-2016 at 12:38 PM.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] crontab does not reread the crontab file upon modification of the latter. stf92 Slackware 4 08-01-2015 06:12 PM
[SOLVED] Problem with crontab:: command not executed properly via crontab Ankush Seth Linux - Newbie 11 11-11-2013 06:25 AM
[SOLVED] Need help to write script for crontab Hdd operation kapz Slackware 7 01-05-2011 07:42 AM
how to write crontab for cpp program so that it accepts input interactively srinivas445 Linux - Newbie 1 10-15-2008 01:09 PM
How to write crontab to check file size and all file in a directory? modpriest Linux - Newbie 1 02-14-2008 06:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration