Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following crontab file:

2 * * * * /bin/date >> /home/jon/date_from_cron.txt

I think this means "run every two minutes". However, it only runs once. Shortly after setting up this crontab file I checked /home/jon/date_from_cron.txt and found that it contained the following:

Tue Jan  8 17:02:01 CST 2013

Ten minutes later, it still contains just that one line.

What am I doing wrong?

EDIT: I've been told to use /2 at the beginning to make the job run every two minutes. But my operating system does not support this. I have tried on both a Mac running Mountain Lion and on an Ubuntu machine. Here is a quote from the internet regarding this: "Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported." So, given that this is not supported on my machines, how can I get a job to run every X minutes?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

If you want the cron job to run every two minutes, it should be /2 * * * * /bin/date >> /home/jon/date_from_cron.txt

http://www.adminschoice.com/crontab-quick-reference

EDIT: Possibly try */2 * * * * /bin/date >> /home/jon/date_from_cron.txt

share|improve this answer
    
Heh, same link as where I was pasting from. :) –  Hennes Jan 8 '13 at 23:16
    
I tried to put a slash at the start of the line, as you suggested, and I got the error: "/tmp/crontab.veZLYWhgT5":0: bad minute crontab: errors in crontab file, can't install –  Jon Crowell Jan 8 '13 at 23:22
    
Then, it would appear that your OS doesn't support "every X minutes." –  Kruug Jan 8 '13 at 23:28
    
@JonCrowell See edit. –  Kruug Jan 8 '13 at 23:31
1  
Thanks, your edit worked. –  Jon Crowell Jan 9 '13 at 2:24
add comment
2   *   *   *    *    /bin/date >> /home/jon/date_from_cron.txt
-   -   -   -    -
|   |   |   |    |
|   |   |   |    +----- day of week (0 - 6) (Sunday=0)
|   |   |   +------- month (1 - 12)
|   |   +--------- day of        month (1 - 31)
|   +----------- hour (0 - 23)
+------------- min (0 - 59)

Will trigger every hour, one two minutes past the hour.

share|improve this answer
    
Thanks for your answer, but see my edit. –  Jon Crowell Jan 8 '13 at 23:29
    
I assume upgrading crond to on which supports it is not an option? Then you can always add 30 (!) cronjob entries. One at 2 past the hour, one at 4 past the hours, one at 6 past ....... Ugly as hell. Please use that only when you have to. –  Hennes Jan 8 '13 at 23:51
add comment

This will run every 15 minutes at 0, 15, 30 and 45 minutes past the hour. It should work with any version of cron:

0,15,30,45 * * * * /bin/date >> /home/jon/date_from_cron.txt

It is left as an exercise to the reader to tediously convert this to every 2 minutes. :)

share|improve this answer
    
Not necessary...*/2 * * * * /bin/date >> /home/jon/date_from_cron.txt –  Kruug Jan 9 '13 at 18:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.