Why doesn't my cron.d per minute job run?
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_dong
It's owned by root, and executable (not sure if either of those matter). And then I did:
sudo service cron reload
And 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.
Solution 1:
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).
Solution 2:
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_dong
The 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_dong
A 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