I'm running a script provided by rehmatworks to install a LetsEncrypt certificate, which (in addition to the initial install) sets up a monthly cronjob to auto renew. Everything installs fine, however, the cron job is failing, and I can't seem to figure out why.
Here is the cron job (from root 'crontab -e'):
@monthly "sudo service nginx-sp stop && yes | letsencrypt --standalone renew &>/dev/null && service nginx-sp start && service nginx-sp reload"
Which fails with a not found
error:
/bin/sh: 1: sudo service nginx-sp stop && yes | letsencrypt --standalone renew &>/dev/null && service nginx-sp start && service nginx-sp reload: not found
Running directly from the command line work fine, however:
sudo service nginx-sp stop && yes | letsencrypt --standalone renew &>/dev/null && service nginx-sp start && service nginx-sp reload
Any ideas why this works from command line, but not via cron?
"command args"
is not the same thing ascommand args
i.e. the shell (sh
) is seeing the quoted string as a single command rather than a command plus its arguments. Aside from that, removesudo
and run it from root's crontab if elevated permissions are required. – steeldriver May 07 '18 at 22:14&>/dev/null
(which is a bashism) to>/dev/null 2>&1
(or change the crontab's shell from /bin/sh to /bin/bash) – steeldriver May 07 '18 at 23:13