73

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

* */4 * * * /cmd.sh
Evan Anderson
  • 141,071
  • 19
  • 191
  • 328
erotsppa
  • 2,033
  • 6
  • 23
  • 24

4 Answers4

79

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...
Evan Anderson
  • 141,071
  • 19
  • 191
  • 328
78
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.

phuzion
  • 2,192
  • 1
  • 18
  • 23
29

Do a crontab -e and then add the following entry

0 */4 * * * path_to_the_script

This will the script every 4 hours.

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