What is the correct syntax to run cron every 4 hours?
Solution 1:
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...
Solution 2:
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.
Solution 3:
Do a crontab -e and then add the following entry
0 */4 * * * path_to_the_script
This will the script every 4 hours.
Solution 4:
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