Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

I have the cron job as shown below, and wanted it to run every 2 hours, but it keeps running every 2 minutes.

Can someone tell me where I'm going wrong?

  
* */2 * * * /path-to-script

share|improve this question

marked as duplicate by Michael Hampton Sep 20 at 14:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4 Answers 4

up vote 87 down vote accepted

An asterisk in the minute (first) field tells it to run every minute, regardless of the other fields.

You need to specify an exact minute to run within the hour. Be that on the hour (0), half past (30), etc..

0 */2 * * * /path-to-script
share|improve this answer
    
that should do it. –  egorgry Jul 21 '09 at 13:27
    
Thanks guys for your swift response :) –  Helen Jul 21 '09 at 13:32
    
Helen, please mark Dan's response as the correct answer :) –  pauska Jul 21 '09 at 13:42

The correct description of what you had

 * */2 * * * /path-to-script

is "run every minute where the hour is a multiple of 2".

Which means 00:00 to 00:59, 02:00 to 02:59, 04:00 to 04:59, ... and so on. Not quite the same as "run every minute". The solution already given is valid though.

share|improve this answer
2  
True, but better posted as a comment to the question, but if you don't have enough reputation, you won't be able to. It's a limitation of the StackExchange platform. –  nalply Dec 9 '10 at 12:56

Off the top of my head, you could try specifying all the hours when it should run:

0 0,2,4,6,8,10,12,14,16,18,20,22 * * * /path-to-script
share|improve this answer
2  
*/2 is much cleaner –  David Pashley Jul 21 '09 at 13:39
7  
*/2 while cleaner, is not portable... does not work on solaris and likely most other unix variants. –  ericslaw Jul 21 '09 at 14:26
    
Good to know. This options has the ability to ignore some of the hours which we may not need to execute the cron. –  BlueBird Jun 8 at 6:35

Also you can do by this

0 0-23/2 * * * /path/to/the/script

or if you want to be more specific on every 2 hours, you can use

0 0,2,4,6,8,10,12,14,16,18,20,22 * * * /path/to/the/script

The hours values should be sparated by commas.

share|improve this answer

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