1,105,409 Community Members

Cron job interval larger than 60 mins

Member Avatar
chophouse
Light Poster
40 posts since Apr 2008
Reputation Points: 25 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

I'm not sure exactly which forum to ask this,so I'm starting here,

I have a cron job I want to execute every 72 minutes. I've researched how to schedule the job for an interval of 60 min or less, but is there a way to specify a minutes interval when the required interval is > 60 ?

Member Avatar
rubberman
Senior Poster
3,999 posts since Mar 2010
Reputation Points: 513 [?]
Q&As Helped to Solve: 501 [?]
Skill Endorsements: 87 [?]
 
2
 

I think you can use a multi-entry crontab like this:

0 0,5,10,15,20 * * * cmd-to-run
12 1,6,11,16,21 * * * cmd-to-run
24 2,7,12,17,22 * * * cmd-to-run
36 3,8,13,18,23 * * * cmd-to-run
48 4,9,14,19 * * * cmd-to-run

Member Avatar
chophouse
Light Poster
40 posts since Apr 2008
Reputation Points: 25 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

How would i use that to define an interval of every 72 minutes ? Not sure I understand.

Member Avatar
DoRight
Light Poster
35 posts since Feb 2013
Reputation Points: 2 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
1
 

Rubberman has you running the command
on the hour for 12 midnight, 5 am, 10 am, etc.
12 mins after the hour for 1 am, 6 am, ...
24 mins after the hour for 2 am, 7 am, ...
etc.
Very clever.

Member Avatar
chris.kelley.5015
Newbie Poster
6 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Rubberman,

I appreciate this post, as it cemented cron methodology in my own mind, something I had previously not fully understood (having never actually used cron before). That being said, in evaluating the lines you provided, I believe I may see a minor problem.

Original post:

0 0,5,10,15,20 * * * cmd-to-run
12 1,6,11,16,21 * * * cmd-to-run
24 2,7,12,17,22 * * * cmd-to-run
36 3,8,13,18,23 * * * cmd-to-run
48 4,9,14,19 * * * cmd-to-run

If I understand this correctly, those lines, as written, will fire at 00:00, 01:12, 02:24, 03:36, 04:48, and then cycle to 05:00, which would be 12 minutes after the 04:48 occurrence rather than 72. Would the following adjustment fix it? Again, this is a newbie trying to understand, so please forgive my any appearance of presumption:

0 0,6,12,18 * * * cmd-to-run
12 1,7,13,19 * * * cmd-to-run
24 2,8,14,20 * * * cmd-to-run
36 3,9,15,21 * * * cmd-to-run
48 4,10,16,22 * * * cmd-to-run

I believe this will make the last occurrence be 22:48, leaving 72 minutes until 00:00, at which point the cron job would then start over again exactly right. Starting at midnight every night, this should run the command every 72 minutes around the clock, assuming one has put the same command in place of cmd-to-run on each line.

Member Avatar
Watael
Junior Poster
134 posts since Apr 2012
Reputation Points: 4 [?]
Q&As Helped to Solve: 27 [?]
Skill Endorsements: 2 [?]
 
0
 

hi,

 for ((n=0; n<24*60;n+=72)); do date -d "00:00 $n min" +%H\ %M; done |\
     awk 'BEGIN{PROCINFO["sorted_in"]="@ind_num_asc"}
          {$1=$1?$1:"00";a[$2]=a[$2]?a[$2]","$1:$1}
          END{for(i in a)printf("%d\t%s\t* * *\tcmd-to-run\n", i, a[i])}'
0       00,06,12,18     * * *   cmd-to-run
12      01,07,13,19     * * *   cmd-to-run
24      02,08,14,20     * * *   cmd-to-run
36      03,09,15,21     * * *   cmd-to-run
48      04,10,16,22     * * *   cmd-to-run
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: