I created a cron job using
* */2 * * * schedule. Can anyone tell me what schedule this refers to?
I guess it should execute every 2 hours, but it seems to execute every minute.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
This is how a cron job is laid out:
minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command An asterisk (*) can be used so that every instance (every hour, every weekday, every month, etc.) of a time period is used.
0 */2 * * * so this will run for every 2 hours,every day and every month...
Cron jobs will execute any time there is a match condition on the time spec. An asterisk (
*) means "all".
So, what you've got with your time spec is:
* */2 * * *
The fields are:
So, what you've specified, in english, is "run once per minute during even numbered hours". Sounds kind of silly, but
cron will faithfully obey.
In order to make it run only once, every other hour you need to set the minute field to some specific number. Any number
60 is fine, but what you don't want is
As many people have already suggested, the following is probably closer to what you want:
0 */2 * * *
Putting your cronjob like that will make it run every minute (first
*) of every hour that's dividable by 2 (the
*/2), so that means it runs every "even" hour, the entire hour. From
2:00 - 2:59,
4:00 - 4:59,
6:00 - 6:59,
8:00 - 8:59,
10:00 - 10:59 and
12:00 - 12:59 both AM and PM.
If you want to run it every 2 hours you should explicitly put the minute counter to
0 */2 * * * user /some/command/here.