0

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.

5 Answers 5

2

You should use 0 */2 * * * for running job every 2 hours

2

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. so use 0 */2 * * * so this will run for every 2 hours,every day and every month...

1

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:

  • minute
  • hour
  • day of month
  • month
  • day of week

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 0-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 * * *
0

I believe you want 0 */2 * * *. See the difference? What you have probably runs every minute every other hour.

0

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, so:

0 */2 * * * user /some/command/here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .