Edit the configuration in BackupPC is as below :
Edit config –> Backup Settings –> User commands -> DumpPostUserCmd as
/theg/email.sh $xferOK $host $type $client $hostIP $share $XferMethod $sshPath $cmdType
where /theg/email.sh is the custom script.
Below are the contents of the email.sh script :
#!/bin/bash
# script to send simple email
# Email To ?
EMAIL=”your_email_address”
# Email text/message
EMAILMESSAGE=”/tmp/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=”SUCCESS”
else
STATUS=”FAILED”
fi
# email subject
SUBJECT=”[BackupPC] $STATUS for host: $client”
# Email text/message
echo “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
/bin/mail -s “$SUBJECT” “$EMAIL” < $EMAILMESSAGE
I needed to change the script a little bit for postfix.
instead of /bin/mail -s “$SUBJECT” “$EMAIL” < $EMAILMESSAGE
i did /usr/sbin/sendmail -v "$EMAIL" "$SUBJECT" < $EMAILMESSAGE
i'm currently running ubuntu 12.04.04 and it didn't came with /bin/mail.
This also works fine.
Thanks for your update Robin !
I followed the link and give me this error ‘Output from DumpPostUserCmd: Exec of /etc/backuppc/email.sh failed’ could you help me!
Check whether you have execute permission
hello where am i going to put that email.sh script ..can you help please elaborate more
You can keep the script wherever you want provided you have the permission. In my case, I created one directory /theg and kept it there .
/theg/email.sh
Hopefully it’s not too late to comment. I’m getting the following when I run the script:
./backuppc_notification_email.sh: line 26: ”FAILED”: command not found
./backuppc_notification_email.sh: line 29: ”/tmp/emailmessage.txt”: No such file or directory
./backuppc_notification_email.sh: line 30: ”/tmp/emailmessage.txt”: No such file or directory
./backuppc_notification_email.sh: line 31: ”/tmp/emailmessage.txt”: No such file or directory
./backuppc_notification_email.sh: line 32: ”/tmp/emailmessage.txt”: No such file or directory
There’s also more of the exact same errors as you see from line number 29 to 41.
I’ve given it executable rights also.
Any suggestions, please?
try to create the missing file and test again:
touch /tmp/emailmessage.txt
Thanks for the quick response. I tried making the file you suggested and I’m still getting the same errors, that the /tmp/emailmessage.txt doesn’t exist when I run the script. And I’m still getting the error “FAILED”: command not found again.
It was the special characters(“” “”). I retyped them in, and it worked. Thank you.
Just a few notes on some things I had to change to make this work:
Change /bin/mail to /usr/bin/mail
Change “ to ” (used notepad find and replace for this)
I saved my script here for easy referece: /etc/backuppc/email.sh
Works beautifully! Thank you so much for this!
I have written that long back, Glad to hear that it still works even after long time.
Not sure if you’re still using Backuppc yourself but I was wondering if there would be a way of including the LOG file contents in the body of the email? That would just be the icing on the cake!
Ps. If you’re not using Backuppc anymore – may I ask what you’re using now and why no longer Backuppc?
Hi i was wondering if someone could shed some light, as for the script some odd reason it wont work keeps telling me
�/tmp/emailmessage.txt�: No such file or directory
i think it has to do with the ” i was reading the comments and i tried no luck a
Thank you
manually check if that file has been created by typing
stat /tmp/emailmessage.txt
if it finds it then type the quotes again from the variable at the top. There is some issue copying and pasting from this website as it changes the quotes into something else when pasting it in terminal.
If it does not exist then it means the script has not created the email message file.
Thanks
Ibrahim
Hello, for some reason i get email through without SUBJECT. I changed /bin/mail to /usr/sbin/sendmail -v “$EMAIL” “$SUBJECT” < $EMAILMESSAGE
Answering to my own question… I had to apped the Subject to the EMAILMESSAGE file when using sendmail.