2

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?

3 Answers 3

4

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

4
  • Heh, same link as where I was pasting from. :)
    – Hennes
    Jan 8, 2013 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
    – tadasajon
    Jan 8, 2013 at 23:22
  • Then, it would appear that your OS doesn't support "every X minutes."
    – Kruug
    Jan 8, 2013 at 23:28
  • @JonCrowell See edit.
    – Kruug
    Jan 8, 2013 at 23:31
2
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.

2
  • Thanks for your answer, but see my edit.
    – tadasajon
    Jan 8, 2013 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, 2013 at 23:51
1

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. :)

1
  • Not necessary...*/2 * * * * /bin/date >> /home/jon/date_from_cron.txt
    – Kruug
    Jan 9, 2013 at 18:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .