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:
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,firstname.lastname@example.org = 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”)
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 email@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!