I have thrown a bunch of darts trying to get a python script of mine to execute every minute. So I thought I'd simplify it to just do the "simplest thing that could could possibly work" once per minute (I'm running debian/testing).
I created a single line file in /etc/cron.d/perminute:
* * * * * /bin/touch /home/me/ding_dongIt's owned by root, and executable (not sure if either of those matter). And then I did:
sudo service cron reloadAnd then sit back and start running ls -ltr again and again in my home directory (/home/me). But my ding_dong file never shows up. I know if I do a sudo /bin/touch /home/me/ding_dong, it shows up right away.
Obviously missing something stupid here.
13 Answers
When adding a cron configuration in /etc/cron.d/ or in /etc/crontab you have to add the username in which context the command should run, in your example
* * * * * root /bin/touch /home/me/ding_dong
And just a hint from me: you don't have to start running ls -ltr again and again, just use watch -n 5 "ls -ltr" and it will run the command every 5 seconds (or any other value by replacing 5 with what you want).
To create a new cron job, you should run crontab -e as the user you want running the job. Then add the relevant line in the editor window that appears:
* * * * * /bin/touch /home/me/ding_dongThe way you are doing it requires a different format and is really not a good idea anyway. Crontabs in /etc/cron.d have a slightly different format, they require a user name to be run under. For example:
* * * * * USERNAME /bin/touch /home/me/ding_dongA good trick (as suggested by @VogonPoetLaureate) is to capture the standard error of your cron jobs which can help debug them. For example:
* * * * * /bin/touch /home/me/ding_dong 2>/tmp/error 6 A possible mistake here is how a single line file is created. From Ubuntu Documentation:
...line has five time-and-date fields, followed by a command, followed by a newline character.
For example, this way of the creation doesn't work:
printf "* * * * * /bin/touch /home/me/ding_dong" > /etc/cron.d/ding_dong