Home > Technical Blog > Send email based on backup joblog keyword

Send email based on backup joblog keyword

1 Star2 Stars3 Stars4 Stars5 Stars
(No Ratings Yet)
Updated 15th June 2023, Rob Morrison

Here’s a handy tip that you may find useful: In order to grep for a key word in the backup joblog and send an email to a selected recipient, we suggest using a script that will grep a keyword (in this example we use the “Will not descend” keyword). Then send the e-mail (in this case to the recipient specified in the “Mail” directive) or any specific e-mail you wish to use.

For example, in the Messages resource, you should have two “MailCommand” directives. One of them will call the script:

Messages {
Name = Default
MailCommand = “/opt/bacula/scripts/send_email.sh %j %t %e %c %l %r”
MailCommand = “/opt/bacula/bin/bsmtp -h localhost -f \”\(Bacula\) \<%r\>\” -s \”Bacula: %t %e of %c %l\” %r”
OperatorCommand = “/opt/bacula/bin/bsmtp -h localhost -f \”\(Bacula\) \<%r\>\” -s \”Bacula: Intervention needed for %j\” %r”
Mail = root@localhost,xx.yyyy@baculasystems.com = All, !Skipped
Operator = root@localhost = Mount
Console = All, !Skipped, !Saved
Append = “/opt/bacula/log/bacula.log” = All, !Skipped
Catalog = All


# cat ../scripts/send_email.sh


joblog=$(echo “llist joblog jobid=$jobid” | /opt/bacula/bin/bconsole)
has_warning=$(echo “$joblog” | grep “Will not descend”)
echo “$has_warning”
if [[ ! -z “$has_warning” ]]; then
echo “$joblog” | /opt/bacula/bin/bsmtp -h localhost -s “Backup reported \”Will not descend\”: $jobtype $jobexitstatus of $jobclient $joblevel” $recipient

If you wish to send these e-mails to a different recipient, you can simply add it in the MailCommand line as an argument to the script:


MailCommand = “/opt/bacula/scripts/send_email.sh %j %t %e %c %l support@example.com”

All the above can be customized with any option for character substitution.

Hope that is helpful. Next technical blog coming your way soon!

Leave a comment

Your email address will not be published. Required fields are marked *