Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I try to execute some command like this:

*/10 0,1 * * * $BPY some_script.py

Meaning I want to run it every 10 minutes between 0:00 and 1:00.

BUT: I see in my /var/log/cron that it is not executed. And more: it is the only one task being not executed (so my cron works well in other cases). Operating sysyem is Debian GNU/Linux 6.0.

What am I doing wrong? Is zero a bad hour?

update: $BPY just holds path to python executable. Other commands also use it and it runs fine.

Well, if it was a realy bad command - it would at least appear in /var/log/cron

update 2: The script works fine with other hours (for example, * * * * * perfectly runs it every minute and it does exactly what I want)

share|improve this question
1  
no, it is not bad hour. is your some_script.py executable? is the $BPY known to the cron? –  Serge Oct 7 '12 at 19:17
    
$BPY is just a variable that holds virtualenv's python path - I should've mention it. It is successfuly used in other commands of this crontab. –  ns-keip Oct 7 '12 at 19:36
    
Your current implementation will not have it run every ten minutes from 12 to 1, instead it will run every ten minutes for both the 12 hour and the 1 hour meaning it will do so for 2 hours (or thereabouts) –  UtahJarhead Oct 7 '12 at 19:59
1  
Even after your second edit, the syntax is within the realm of what cron accepts. However, per your initial description of wanting it to run from 12 to 1, remove the ,1 so it only read '0' since the current 0,1 will have it running from 12 to just before 2am. –  UtahJarhead Oct 7 '12 at 20:03
add comment

1 Answer

It looks like the cron does not have $BPY defined. Is it some_script.py that needs to be executed? What's the purpose of $BPY? Also, you should probably need the full path of the script, not just the script's name itself.

Assuming that some_script.py is the real intended executed script, then try just executing that (with the full path!!)

In your comments below this answer, you said the $BPY is Python's path. Instead of doing that, you should use a shebang to specify the full path of the interpreter that is to be used. A common shebang specifying python is: #!/usr/bin/python. This should be the first line of your some_script.py file.

As far as the syntax...

Cron format is a simple, yet powerful and flexible way to define time and frequency of various actions.

cron format consists of fields separated by white spaces:

[Min] [Hr] [Day of Month] [Month of Year] [Day of Week]

The following diagram shows what it consists of:

* * * * *
| | | | |
| | | | +---- Day of the Week   (range: 0-6, 0 standing for Sunday; Mon,Tue, etc.
| | | |                          Most OS's recognize Sunday as 0 or 7)
| | | +------ Month of the Year (range: 1-12 or Jan, Feb, etc)
| | +-------- Day of the Month  (range: 1-31)
| +---------- Hour              (range: 0-23)
+------------ Minute            (range: 0-59)

Any of these 6 fields may be an asterisk (*). This would mean the entire range of possible values, i.e. each minute, each hour, etc. In the first four fields.

Any field may contain a list of values separated by commas, (e.g. 1,3,7) or a range of values (two integers separated by a hyphen, e.g. 1-5).

After an asterisk (*) or a range of values, you can use character / to specify that values are repeated over and over with a certain interval between them. For example, you can write 0-23/2 in the Hour field to specify that some action should be performed every two hours (it will have the same effect as 0,2,4,6,8,10,12,14,16,18,20,22). A value of */4 in the Minute field means that the action should be performed every 4 minutes. 1-30/3 means the same as 1,4,7,10,13,16,19,22,25,28.

In Month and Day of Week fields, you can use names of months or days of weeks abbreviated to first three letters (Jan,Feb,...,Dec or Mon,Tue,...,Sun) instead of their numeric values.

Alternatively, you can use special keywords in lieu of the first 5 fields specified above:

string         meaning
------         -------
@reboot        Run once, at startup.
@yearly        Run once a year, "0 0 1 1 *".
@annually      (same as @yearly)
@monthly       Run once a month, "0 0 1 * *".
@weekly        Run once a week, "0 0 * * 0".
@daily         Run once a day, "0 0 * * *".
@midnight      (same as @daily)
@hourly        Run once an hour, "0 * * * *".

This alternate format is not supported in older, proprietary operating systems like SCO Unix.

share|improve this answer
    
$BPY is just a variable that holds virtualenv's python path - I should've mention it. It is successfuly used in other commands of this crontab. –  ns-keip Oct 7 '12 at 19:37
    
In that case, just change the first line of the path to python's location: #!/usr/bin/python (or whatever it is) –  UtahJarhead Oct 7 '12 at 19:39
    
Updated the answer to reflect the purpose of $BPY. –  UtahJarhead Oct 7 '12 at 19:48
    
Using shebang would be inconvinient, because I use virtualenvs on different machines - so developer would have to syncronize his paths to server :( –  ns-keip Oct 7 '12 at 19:52
    
Perhaps as a debugging issue, you can have it spit out the value it has for $BPY to a text file. "echo $BPY > /tmp/bpy.txt" –  UtahJarhead Oct 7 '12 at 19:55
show 1 more 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.