** Mark Rogers mark@quarella.co.uk [2011-08-10 09:57]:
I have a script, /etc/init.d/xxx, which I want to restart at 3am every morning.
If I use sudo crontab -e
.. and add MAILTO=<my email> 0 3 * * * /etc/init.d/xxx restart
.. I get an email at 3am telling me that start-stop-daemon can't be found, so I assume that the environment isn't set up correctly?
If I try creating: /etc/cron.d/xxx comprising MAILTO=<my email> 0 3 * * * root /etc/init.d/xxx restart .. then restart crond, I get no email and nothing appears to happen (I've tried with/without the MAILTO).
On the other hand, just straight editing /etc/crontab and adding MAILTO=<my email> 0 3 * * * root /etc/init.d/xxx restart .. works a treat.
I don't want to be directly editing /etc/crontab so where am I going wrong?
Note that /etc/init.d/xxx is hand-crafted so could well be at fault here.
** end quote [Mark Rogers]
It could be down to permissions, or possibly the script itself is assuming it is running in a particular directory which is different depending on how you run it. You are working with two different crontab files. The first one (sudo crontab -e) will be editing the crontab for root which is in /var/spool/cron/crontabs/root as opposed to the /etc/crontab file.