5

I set my cron job via crontab -e, with the following code:

* */1 * * * python /var/www/your_script >/dev/null 2>&1

I didn't add .py extension as it makes the cron job invalid.

However, after logging it by grep CRON /var/log/syslog, the script is executed every one minute, not every one hour.

Mar  1 07:40:01 my-instance CRON[4471]: (me) CMD (python /var/www/your_script >/dev/null 2>&1)
Mar  1 07:41:01 my-instance CRON[4474]: (me) CMD (python /var/www/your_script >/dev/null 2>&1)
Mar  1 07:42:01 my-instance CRON[4477]: (me) CMD (python /var/www/your_script >/dev/null 2>&1)

Why does my script start to be run every one minute, not every one hour? My environment is Ubuntu 16.04.

2
  • 7
    No, you set it to every minute of every hour. Pick a fixed minute for the first column. – muru Mar 1 '17 at 7:47
  • Or you could use 0 * * * * which means 0 minutes after every full hour. – IQV Mar 1 '17 at 7:57
9

If you want to set cronjob for every hour, you can do it any of following way:

You can run:

0 * * * * /path/to/script

which reads

On minute 0, each hour, each day of month, each month, each day of the week.

or

@hourly /path/to/script

or

0 */1 * * * /path/to/script

An asterisk (*) can be used so that every instance (every hour, every weekday, every month, etc.) of a time period is used.

Reference: crontab, CronHowto

8
  • 1
    Thanks. So are 0 */1 * * * and 0 * * * * the same in this case? – Blaszard Mar 1 '17 at 8:06
  • Hmmmm I'm pretty confused now. So is this answer wrong? The question is how to run the script every 6 hours and the answer is 0 */6 * * *. – Blaszard Mar 1 '17 at 8:13
  • Also, then how about 0 1 * * *? I though it is "run at every 1 am". Maybe am I wrong? – Blaszard Mar 1 '17 at 8:14
  • Answer is correct. Every 6 hour - */6 or means 0,6,12,18,0 or 12 – d a i s y Mar 1 '17 at 8:19
  • 4
    @Lnux "No, it will run at every 1 am." - No it won't; */1 is identical to *, so 0 */1 * * * means every hour. – marcelm Mar 1 '17 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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