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:

—–8<—–
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) ” -s ”Bacula: %t %e of %c %l” %r”
OperatorCommand = “/opt/bacula/bin/bsmtp -h localhost -f ”(Bacula) ” -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
#!/bin/bash

jobid=$1
jobtype=$2
jobexitstatus=$3
jobclient=$4
joblevel=$5
recipient=$6

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
fi
—–8<—–

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:

—–8<—–

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

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

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