Add Subject variable to Crontab

Below script is working fine for me and send out mail to the respective recipient.
MAILTO=""

43 6 * * * certbot renew --post-hook “systemctl reload httpd” --quiet.

but my requirement is to add a subject and multi-recipient.
is there any quick modification which I can do in script to get the desired output.

In the --deploy-hook script you can use the $RENEWED_LINEAGE and $RENEWED_DOMAINS variables. Perhaps you could use that hook to send the e-mails.

it would be better for me if you can edit the existing script. I don’t know how to use $renewed_lineage variable and where I should put.

and above script is not working with a group distribution list too.
can below script work for me.
MAILTO="abcd@gmail.com" Subject=“certbot renew failed”
43 6 * * * certbot renew --post-hook “systemctl reload httpd” --quiet

You are using cron to send emails, your subject will be

Cron <user@hostname> your_command

this will be sent if your command has some output.

If your command doesn’t have output (you are using --quiet) no email is sent.

This means that in your current configuration, you should just add your email address in the MAILTO variable and leave it alone, because you will only get an email if renewal fails:

If you’re sure that this command executes successfully without human intervention, you can add the command to crontab (since certificates are only renewed when they’re determined to be near expiry, the command can run on a regular basis, like every week or every day). In that case, you are likely to want to use the -q or --quiet quiet flag to silence all output except errors.

You should check if you can get emails from your server, though. Run

echo "Hi, ${USER}! I'm ${HOST}" | mail -s "This is the subject" youraddress@example.com

and check if you get the email or errors.

1 Like

As per your Suggestion. we can’t add subject to the crontab manually.

echo “Hi, {USER}! I'm {HOST}” | mail -s “This is the subject” youraddress@example.com

above script giving below error :

STOREDRV.Submission.Exception:SendAsDeniedException. MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message.

Where did you put that? You did run it on an actual shell, did you? You don’t need to run that command if you are sure you can get emails from your server.

I ran the command in the shell. please help me to add subject variable in crontab.
Also can we send mail to group distribution list .
Currently Running Script :

MAILTO=""
43 6 * * * certbot renew --post-hook “systemctl reload httpd” --quiet

There is no such feature in crond.

You can write it yourself by messing with crond config, but I don’t think it’s worth it. You’d have to write a script to rewrite the email and then send it.

Writing script is complicated and play with config file .
Thank you for your time and effort.

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