I would like to automate the running of this command (which is simple enough):

~/dehydrated/dehydrated --cron --domain www.mydomain.com --out . --challenge http-01

The problem is that I need to email my current host every time the certs renew so that they can implement the changes in the backend (very inefficient, I know, but there is no other way as only they have root access).

When I run the command above, it checks whether the current date is greater/less than 7 days from the certificate expiry date. When the time difference is greater it will return:

Processing www.mydomain.com
 + Checking domain name(s) of existing cert... unchanged.
 + Checking expire date of existing cert...
 + Valid till May  9 19:27:44 2018 GMT (Longer than 7 days). Skipping renew!

Whereas when the time difference is smaller it will renew the certs.

What I would like to do is make the script run every day. When the output is "Skipping renew" I'd like it to do nothing and close, and when the certificates do renew, I'd like to chain in another command (maybe with &&?) that sends an email to the hosts. I've already set this command up in python with a management command (python manage.py email_hosts).

~/dehydrated/dehydrated --cron --domain www.mydomain.com --out . --challenge http-01 | grep -q 'Skipping renew' || python manage.py email_hosts


  • |: pipe the output of your initial command to the next command. This is assuming that it writes to standard out.
  • grep -q 'Skipping renew': search for Skipping renew in the output of the command before the pipe |. Act in "quiet" mode -q, i.e. don't actually show the match on the command line.
  • || If the previous command fails (i.e. there is no match), then run the following command (i.e. email). This is essentially the opposite of &&. If the previous command matches something, then the email command won't run.


You can also test the logic of the command flow with something like the following:

echo 'Skipping renew' | grep -q 'Skipping renew' || echo Mailing
echo 'Something else' | grep -q 'Skipping renew' || echo Mailing
  • 1
    Thanks @Sparhawk - works like a charm! Have a +1 and an accepted answer ;) – DDiran Feb 15 '18 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.