I know how to execute multiple command in one crontab line but I can't understand why my last command is not being executed. My (root) crontab is like
5 0 1,15 * * echo $(date) >> /root/certbot_cronjob_log.txt && /usr/services/certbot/certbot-auto renew --text >>/root/certbot_cronjob_log.txt 2>&1 && service nginx restart
What I want to achieve: Write the current date to file certbot_cronjob_log.txt, then run the autorenew script "certbot-auto", write it's output into the file and then restart nginx.
It does everything until the point "restart nginx". When I run exactly this whole command in my terminal (as root) it is working and nginx restarts.
I already tried this:
5 0 1,15 * * bash -c 'echo $(date) >> /root/certbot_cronjob_log.txt && /usr/services/certbot/certbot-auto renew --text >>/root/certbot_cronjob_log.txt 2>&1 && service nginx restart'
Any ideas?
/usr/sbin
(where theservice
command lives) isn't in the crontab path - same likely applies to/sbin/restart
. (Even if you move your commands to a separate script you will need to address this, either by using full paths to the executables or by defining a suitablePATH
) – steeldriver Jul 14 '17 at 12:11/usr/sbin/service nginx restart
did the trick! – Lean-Juc Dicarp Jul 14 '17 at 13:07