If I execute this .sh file root@aaa:~# ./letsencrypt.sh or root@aaa:~# /root/letsencrypt.sh it does the job.
Now I want that script to be executed everytime certbot renew the letsencrypt certificate so I added the following line in the file /etc/letsencrypt/renewal/my.domain.conf : renew_hook = /root/letsencrypt.sh
Unfortunatly, it doesn't work. When I look at logs just after the renewal of the letsencrypt certificate by certbot, I find :
I'll try, check if it works for the next renewal which is supposed to happen tonight and let you know if that solve the problem.
I also change renew_hook = /root/letsencrypt.sh
into renew_hook = bash /root/letsencrypt.sh
When performing a test run using --dry-run or reconfigure, run any applicable deploy hooks. This includes hooks set on the command line, saved in the certificate's renewal configuration file, or present in the renewal-hooks directory. To exclude directory hooks, use --no-directory-hooks. The hook(s) will only be run if the dry run succeeds, and will use the current active certificate, not the temporary test certificate acquired during the dry run.
I dunno guys... I'd simplify it a bit: (requires ssh key access)
Secure copy is easier to wrap your head around than secure ftp. Assuming sftp is not the only means of access.
scp -p -P "$DEST_PORT" /etc/letsencrypt/live/my.domain/fullchain.pem' root@"$DEST_SERVER":/path/to/where/you/want/it/to/go/fullchain.pem
-p = preserve attributes
-P "$DEST_PORT" = replace with your destination port (hopefully not 22)
root@"$DEST_SERVER" = USER@my.domain
post_hook runs on everycertbot renew invocation regardless whether or not the certificate was actually renewed. renew_hook runs only when there was a successful renewal.