Cron Not Working Due To Multi Line Bash Script not Using Correct Syntax

#!/bin/sh
/opt/letsencrypt/letsencrypt-auto renew --agree-tos --email mtwebink@gmail.com
–post-hook “/usr/sbin/service nginx-sp reload”

Renews the cert but doesn’t restart nginx, as far as I can tell the path is correct, usr sits in root… followed by sbin and service

Ubuntu 14.04.4 x64

Digital Ocean

I’m using Putty on Windows 10

Maybe it’s because the beginning of --post-hook starts on a separate line! I’ve put everything on one line now. Do you think this is probably the issue?
Thanks.

Hi @MikeThomasDev,

Is this a script that you put in /etc/cron.daily or something?

What authentication method are you using? What command did you originally run to get the certificate?

Do you get an error message anywhere or just see nginx not running afterward? Is there any error in the nginx logs? What happens if you run /usr/sbin/service nginx-sp reload yourself as root?

Newlines are definitely command separators in the shell, so if it was literally a separate line, then likely yes!

Thanks schoen, yeah I’ll keep an eye on it but hopefully it’ll work this time. Thanks again!

Hi @MikeThomasDev

Your diagnosis is exactly right

Review the correct multiline bash command syntax here: http://stackoverflow.com/questions/18599711/how-can-i-split-a-shell-command-over-multiple-lines-when-using-an-if-statement

Andrei

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.