Adding or editing to apply other commands within the cron job builtin

Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g., so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is: N/A

I ran this command:
It produced this output:
a new certificate in the area it had designated
My web server is (include version):
NA / uses Cloudflare tokenized
The operating system my web server runs on is (include version):
Cloudflare Tokenized
My hosting provider, if applicable, is:
DNS = cloudflare
I can login to a root shell on my machine (yes or no, or I don’t know):
I’m using a control panel to manage my site (no, or provide the name and version of the control panel):
The version of my client is (e.g. output of certbot --version or certbot-auto --version if you’re using Certbot): version 2.8.7

Guys i setup the cron job to renew the certificate every 3 months and this works well
here is the cron job

18 0 * * * “/Users/username/”/ --cron --home “/Users/username/” > /dev/null

The issue i have is that the .domain.cer and key that is created /replaced needs to be placed into a directory on another hardware and renamed over ssh and the server service STOPPED whilst this happens … i do the whole thing by creating an executable bash script and run it manually after the crontabed cronjob has run … key word being MANUALLY … is it possible to ammend the existing script itself to do this all in one so i dont have to manually run a second script ? example of the secondary script :

/Users/user/ --issue --dns dns_cf -d
/usr/local/server/mailserver/mailserver stop
scp /Users/user/ root@
scp /Users/user/ root@
/usr/local/server/mailserver/mailserver start

Please if anyone can asssist on how to do this in one and using the inbuilt cron job ! And also which script to alter / edit … im not sure from the cron job which script its referencing (expecting the inside the directory

This is basically the idea in deploy hooks:

You will want to make your own and call it using --deploy -d --deploy-hook <hook name>. will then automatically call it at every renewal.

You can find a template here:

1 Like

Thanks @_az but theres nothing stopping me also just timing the script to run on change less the certificate call so (i dont want to re invent the wheel here) :

/usr/local/server/mailserver/mailserver stop
scp /Users/user/ root@
scp /Users/user/ root@
/usr/local/server/mailserver/mailserver start

  These parameters are to install the cert to nginx/apache or any other server after issue/renew a cert:
  --cert-file <file>                Path to copy the cert file to after issue/renew..
  --key-file <file>                 Path to copy the key file to after issue/renew.
  --ca-file <file>                  Path to copy the intermediate cert file to after issue/renew.
  --fullchain-file <file>           Path to copy the fullchain cert file to after issue/renew.
  --reloadcmd <command>             Command to execute after issue/renew to reload the server.

So if the machine on which you run has passwordless (key or cert) ssh access to the machine you want to deploy to, you can do this: -i -d $DOMAIN_NAME [--ecc] --reloadcmd "ssh user@otherserver /path/to/script/on/other/"

of course you also can: -i -d $DOMAIN_NAME [--ecc] --reloadcmd "/path/to/script/on/local/"

and use that script to scp and reload

1 Like

why not use ssh deploy hook?

it seems convoluted and restricted as opposed to running your own script with the a server software you know responds to the script you originally ran ?

Because I did’t know of this feature:

export DEPLOY_SSH_REMOTE_CMD=command to execute on remote host

but wait, does remember environment variables when renewing, or do I have to set them each time?

does remember environment variables when renewing

Yes, of cause

1 Like

So for something that normally would run as a standalone script and connects keyless and changes the certificate extension (.cer to .crt) such as :
/usr/local/server/mailserver/mailserver stop
scp /Users/user/ root@
scp /Users/user/ root@
/usr/local/server/mailserver/mailserver start
How can i convert that into your deploy hook ? That is literally the actual script i run above manually …
I cant get my head round the arguments to emulate that using deploy hook, otherwise i would use it 100% !

Neil would this work for my scenario ? your feedback and time is very appreciated, the remote command is the main issue i struggle with this is on OSX and the service is kerio connect (does not have “restart” command only stop and start) there is also no example be it linux or other on your page

original script currently in use :
/usr/local/server/mailserver/mailserver stop
scp /Users/user/
scp /Users/user/ root@
/usr/local/server/mailserver/mailserver start --deploy -d --deploy-hook ssh
export DEPLOY_SSH_USER=root
export DEPLOY_SSH_CMD=“ssh -p 22022”
export DEPLOY_SSH_KEYFILE="/usr/local/server/mailserver/sslcert/server3.key"
export DEPLOY_SSH_CERTFILE=/“usr/local/server/mailserver/sslcert/server3.crt”
export DEPLOY_SSH_CAFILE=filename for intermediate CA file
export DEPLOY_SSH_FULLCHAIN=filename for fullchain file
export DEPLOY_SSH_REMOTE_CMD="/usr/local/server/mailserver/mailserver stop sleep 1.5m /usr/local/server/mailserver/mailserver start"
export DEPLOY_SSH_BACKUP=“yes”