Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

5 Answers

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 * * *
share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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...

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.