What is the correct syntax to run cron every 4 hours? [duplicate]
I have the following syntax (which I think is correcT?) but it runs the command every minute!
* */4 * * * /cmd.sh
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.
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...