How to do a cron job every 72 minutes

smith picture smith · Apr 14, 2009 · Viewed 15.5k times · Source

How would I get a cron job to run every 72 minutes? Or some not so pretty number like that?

Answer

lc. picture lc. · Apr 14, 2009

Since cron runs jobs time-based, not interval-based, there's no blindingly simple way to do it. However, although it's a bit of a hack, you can set up multiple lines in crontab until you find the common denominator. Since you want a job to run every 72 minutes, it must execute at the following times:

  • 00:00
  • 01:12
  • 02:24
  • 03:36
  • 04:48
  • 06:00
  • 07:12
  • ...

As you can see, the pattern repeats every 6 hours with 5 jobs. So, you will have 5 lines in your crontab:

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

The other option, of course, is to create a wrapper daemon or shell script that executes and sleeps for the desired time until stopped.