0

I am using a cron to execute a python script every 15 minutes during the day. At nighttime it should only run every hour.

I made 2 entries for this:

0 23-5 * * * python /var/www/script.py > /dev/null 2>&1
*/15 6-22 * * * python /var/www/script.py >/dev/null 2>&1

The one running during the day works fine. This is the last entry from that script in /var/log/syslog:

Jan 26 22:45:01 web CRON[20278]: (sysadmin) CMD (python /var/www/script.py > /dev/null 2>&1)

But there are no entries for that script after 23:00. The next entry from that script is:

Jan 27 06:00:01 web CRON[26367]: (sysadmin) CMD (python /var/www/script.py > /dev/null 2>&1)

And that is the "day-cron"-entry starting again. Both entries are made in the same crontab of the user "sysadmin".

Any ideas what the problem here is? Or where else I could look for clues?

I am running Ubuntu 16.04.1 LTS - 4.4.0-42-generic.

1
  • I don't think '23-5' is valid in crontab. Try 23,0-5
    – ridgy
    Jan 27, 2017 at 10:12

1 Answer 1

2

Change 23-5 to 23,0,1,2,3,4,5 or you can add two lines like so:

0 23 * * * python /var/www/script.py > /dev/null 2>&1
0 0-5 * * * python /var/www/script.py > /dev/null 2>&1

Or even as others have said (I forgot you can mix and match):

0 23,0-5 * * * python /var/www/script.py > /dev/null 2>&1

The reason why? Because 23-5 is not a valid range. The range must be from low value to high value only.

0

You must log in to answer this question.

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