1

I would like an email notification everytime a successful backup has taken place using BackupPC which I have installed on Ubuntu 16.04 server. BackupPC doesn't email you notifications unless a backup has failed. When I run the following script, I get the email saying its "failed".

I place the following in the backup settings:

$Conf{DumpPostUserCmd} = 

/var/lib/backuppc/backuppc_notification_email.sh $xferOK $host $type 
$client $hostIP $share $XferMethod $sshPath $cmdType 

And here is the shell script:

#!/bin/bash
# script to send simple email
# Email To ?
EMAIL="[email protected]"
# Email text/message
EMAILMESSAGE="/var/lib/backuppc/emailmessage.txt"
# Grab the status variables
xferOK=$1
host=$2
type=$3
client=$4
hostIP=$5
share=$6
XferMethod=$7
sshPath=$8
cmdType=$9

# Check if backup succeeded or not.
if [[ $xferOK == 1 ]]; then
        STATUS="has been SUCCESSFUL"
else
        STATUS="has FAILED"
fi

# email subject
SUBJECT="[BackupPC] $STATUS for host: $client"

# Email text/message
echo "The filesystem backup for $host $STATUS" > $EMAILMESSAGE
echo "-----------------------------------------" >>$EMAILMESSAGE
echo "Type: $type" >>$EMAILMESSAGE
echo "Client: $client" >>$EMAILMESSAGE
echo "Host: $host" >>$EMAILMESSAGE
echo "Host IP: $hostIP" >>$EMAILMESSAGE
echo "Share: $share" >>$EMAILMESSAGE
echo "XferMethod: $XferMethod" >>$EMAILMESSAGE
echo "sshPath: $sshPath" >>$EMAILMESSAGE
echo "cmdType: $cmdType" >>$EMAILMESSAGE

# send an email using /bin/mail
/usr/sbin/sendmail -v "$EMAIL" "$SUBJECT" < $EMAILMESSAGE

The following is the email message I receive:

The filesystem backup for  has FAILED
-----------------------------------------
Type: 
Client: 
Host: 
Host IP: 
Share: 
XferMethod: 
sshPath: 
cmdType: 

I would like to know why the email doesn't have the relevant information as stated in my shell script, and why it says FAILED?

1 Answer 1

0

Try quoting command and add semicolon in the end:

 $Conf{DumpPostUserCmd} = '/var/lib/backuppc/backuppc_notification_email.sh $xferOK $host $type $client $hostIP $share $XferMethod $sshPath $cmdType';

From BackupPC Documentation:

The configuration file is a perl script that is executed by BackupPC, so you should be careful to preserve the file syntax (punctuation, quotes etc) when you edit it. It is recommended that you use CVS, RCS or some other method of source control for changing config.pl.

Also, you can use here document for creating email message:

cat << _EOF_ > "$EMAILMESSAGE"
The filesystem backup for $host $STATUS 
-----------------------------------------
Type: $type
Client: $client
Host: $host
Host IP: $hostIP
Share: $share
XferMethod: $XferMethod
sshPath: $sshPath
cmdType: $cmdType
_EOF_

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.