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.
On 10 Aug 2011, at 09:55, Mark Rogers wrote:
.. 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?
# which start-stop-daemon /sbin/start-stop-daemon
Note that /etc/init.d/xxx is hand-crafted so could well be at fault here.
Most scripts in /etc/init.d seem to set their PATH explicitly to include /sbin. Try that.
-- Martijn
On 10/08/11 10:08, Martijn Koster wrote:
Most scripts in /etc/init.d seem to set their PATH explicitly to include /sbin. Try that.
Thanks, that's done the trick.
Frustratingly, I pretty much worked out for myself that I needed to set the path, but thought that this was a sign I was doing something wrong as I shouldn't have needed to. The simple check of looking to see if other scripts set the path would have told me that this is "normal"!
** 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.