I am only an hour into learning how cron jobs work, and this is what I have done so far. I’m using crontab -e to add my cron command, which is:
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 don’t see anything in the log file. Can someone please explain what am I doing wrong?
Experiment shows that the
0/1seems to be the problem.0/1should be equivalent to*. If you replace0/1with*, it should work.Here’s my experimental crontab:
This creates
cron1.logbut notcron0.log.I’ll look into this and try to figure out why
0/1isn’t working, but for now just use*and it should work.Update:
The
foo/barsyntax is specific to the Vixie cron implementation, which is used by most Linux systems and by MacOS X but is not universal.The usual way to run a command every minute is to specify just
*in the first field. To run a command every 5 minutes, if your cron supports it, specify*/5.Here’s what the
crontab(5)man page says:I’m not even sure what
0/1means.UPDATE 2:
Ok, here’s what I’ve found.
Given that fields 2 through 5 are all
*, setting the first field (specifying minutes) to*causes the job to run once a minute.*/2runs every 2 minutes, and*/3runs every 3 minutes. This is all as expected.Setting the first field to any of
0/1,0/2, or0/3causes the job to run only at the top of the hour, i.e., it’s equivalent to just0.This is not what I would have expected from the description in the man page. The Wikipedia quote in jgritty’s answer:
doesn’t seem to be entirely correct, at least for the version of Vixie cron I’m using; the
0/1is accepted without complaint, but it doesn’t mean what I’d expect and it doesn’t seem particularly useful.