Hi cron world is not working

I only have an hour to learn how cron works, and this is what I have done so far. Im using crontab -e to add my cron command, which:

0/1 * * * * /usr/bin/python /home/my_username/hello.py > /home/my_username/log.txt

crontab -l confirms that my command is there.

Hello.py:

 #!/usr/bin/python # Hello world python program print "Hello World!" 

But I do not see anything in the log file. Can someone explain what I'm doing wrong?

+6
source share
2 answers

The experiment shows that the problem is 0/1 .

0/1 should be equivalent to * . If you replace 0/1 with * , it should work.

Here is my experimental crontab:

 0/1 * * * * echo 0/1 >> cron0.log * * * * * echo star >> cron1.log 

This creates cron1.log , but not cron0.log .

I will review this and try to understand why 0/1 does not work, but for now, just use * and it should work.

Update:

The foo/bar syntax is specific to the Vixie cron implementation, which is used by most Linux systems and MacOS X, but not universal.

The usual way to run a command every minute is to specify only * in the first field. To run the command every 5 minutes, if your cron supports it, specify */5 .

Here's what the crontab(5) page says:

Step values ​​can be used in combination with ranges. Following the range with /<number> indicates passing the value of the number through the assortment. For example, 0-23/2 can be used in the hours field to indicate command execution every hour (alternative in V7 standard 0,2,4,6,8,10,12,14,16,18,20,22 ). Steps are also allowed after the asterisk, so if you want to say "every two hours," just use */2 .

I'm not even sure what 0/1 means.

UPDATE 2:

Ok, that’s what I found.

Given that fields 2 through 5 are all * , setting the first field (with minutes) to * forces the task to run once a minute. */2 is executed every 2 minutes, and */3 - every 3 minutes. This is all as expected.

Setting the first field to any of 0/1 , 0/2 or 0/3 makes the task work only at the top of the hour, that is, it is equivalent to just 0 .

This is not what I expected from the description on the manual page. Wikipedia quote on jgritty answer :

Some versions of cron may not accept a value preceding "/" if it is not a range, such as "0". An alternative would be replacing zero with an asterisk.

doesn't seem to be quite correct, at least for the version of Vixie cron that I'm using; 0/1 accepted without complaint, but this does not mean what I expect, and it does not seem particularly useful.

+3
source

0/1 seems to be incorrectly formatted for your cron version.

I found this on wikipedia :

Some versions of cron may not accept values ​​preceding "/" if it is not a range, such as "0". An alternative would be replacing the zero with an asterisk.

So, Keith Thompson's answer should work, and therefore should:

*/1 * * * *

+1
source

All Articles