66

I have the following syntax (which I think is correcT?) but it runs the command every minute!

* */4 * * * /cmd.sh
  • 14
    0 */4 * * * /cmd.sh - your problem was the * in the first column. – Suman Feb 28 '13 at 21:48
67
0 0,4,8,12,16,20 * * * /cmd.sh

That's probably how I would do it. This will run the job every 4 hours, on the hours of 00:00, 04:00, 08:00 12:00, 16:00, 20:00.

This is just a little more verbose way of writing */4, but it should work the same.

| improve this answer | |
  • Yeah i really like this way its super easy to read. – Nicholas DiPiazza Jan 30 '15 at 4:52
76

The original post, prior to editing, showed the configuration as:

  • */4 * * * /cmd.sh

The poster wasn't familiar with Markdown and put an asterisk in the first column, causing it to appear as a bullet. I edited their post to reflect what they intended to post:

* */4 * * * /cmd.sh

In that configuration the poster would get the behavior they observed: The job will run once per minute during hours that are evenly divisible by 4.

To avoid running once per minute a number is needed in the first column, like this:

15 * * * * whatever...

That will run on the 15th minute after every hour.

Putting that all together: To run once per hour during hours that are evenly divisible by 4 use this syntax:

15 */4 * * * whatever...
| improve this answer | |
  • 2
    You must have misread the question, the command is supposed to run every four hours, not four times per hour. – phuzion Jul 10 '09 at 16:34
  • His original formatting made it look wrong. Look at my edits. – Evan Anderson Jul 10 '09 at 16:34
  • 1
    Evan is correct. 0 */4 * * * <cmd> would run on the hour every 4th hour. – pauska Jul 21 '09 at 13:45
29

Do a crontab -e and then add the following entry

0 */4 * * * path_to_the_script

This will the script every 4 hours.

| improve this answer | |
9

The problem is the * in the first column

' * */2 * * * /path-to-script '

this translates into run each minute of the hour, but only do it every 2 hours

| improve this answer | |

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