How would I get a cron job to run every 72 minutes? Or some not so pretty number like that?
-
Why does it have to be 72 minutes? – Zifre Apr 14 '09 at 00:32
-
Doesn't have to be, just something that's not a nice even number. – Apr 14 '09 at 00:39
7 Answers
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.

- 113,939
- 20
- 158
- 187
Use at (man at). Have your app or startup script calculate a startup time 72 minutes in the future and schedule itself to run again before it starts working.
Available on windows xp and vista too.
Here's an example for gnu/linux: at -f command.sh now + 72 minutes

- 4,852
- 1
- 22
- 17
-
1
-
1Hopefully this becomes the accepted answer. Once you have the job started it can reschedule itself every time it runs. You might find that you get out of sync, however; so make sure you reschedule your at job as the first thing in your script rather than the last. – Adam Hawes Apr 24 '09 at 00:26
You could always take the approach of triggering cron every minute, and having your script exit out immediately if it's been run more recently than 72 minutes ago.

- 176,543
- 40
- 303
- 368
Don't use cron...
#!/bin/sh
while [ true ]
do
sleep 4320
echo "Put your program here" &
done

- 357
- 2
- 2
-
1Be careful if the program crashes, you'll need to restart it. Also, after a machine reboot, the program will not be running, you'll have to start it. – Adrian Smith Jan 07 '11 at 16:08
-
Yes, better off making it a daemon and using monit for example to keep it running. – mahemoff Apr 08 '13 at 12:18
You cannot directly do this from cron/crontab.
Cron jobs are run on a specific schedule, not on a specific interval.
One alternative would be to work out a schedule that approximated your "every 72 minutes" by running at midnight, 1:12, 2:24, 3:36, ..., and stretching it out to approximate hitting up at midnight. Your crontab file could specify all of these times as times to execute.
Another alternative would be to have a separate application handle the scheduling, and fire your application.

- 554,122
- 78
- 1,158
- 1,373
You'll need to set exactly 20 tasks for this - i.e. set one at 00:00, next one at 01:12, next one at 02:24, etc.
20 iterations make a full day.
Unfortunately, this is the only way to do it, as cron tasks are set up in a fixed schedule beforehand instead of being run, say, "after X minutes the last task was executed".

- 24,920
- 5
- 67
- 85
Uh I know this is long overdue, but I was looking at some scheduling issues and saw this question.
Just do this in your crontab
*/72 * * * * /home/script.sh

- 867
- 8
- 12
-
1This will not work, minutes are 0-59 and anything over 30 minutes will post at x past, ie 34 will post at 34 mintues past, not every 34 minutes. – omega1 Sep 20 '16 at 18:44
-
I just tested this and the result of `*/72 * * * * date >> cron-over-72.out` under CentOS 7 is the job runs one time per hour, on the hour. – CODE-REaD Feb 05 '20 at 21:49