0

I'm using BackupPC and I've made a script that will email me a notification every time a backup has occurred, whether it's successful or has failed. In this script, I would like to extract the last statement from the LOG file. However, my script is echoing out a string to the actual LOG file in BackupPC, and I don't know how/why it's doing that.

#!/bin/bash
# Script to send email notification when BackupPC has performed a backup
sleep 30
# Email To ?
EMAIL="myemail@mydomain.com"

# Email text/message
EMAILMESSAGE="/var/lib/backuppc/emailmessage.txt"

DATE=$(date +%m%Y)

#Grab the status variables
xferOK=$1
host=$2
type=$3
client=$4
hostIP=$5
share=$6
XferMethod=$7
sshPath=$8
cmdType=$9

#Extract the last line of the log for error reporting
LOG_FILE="/var/lib/backuppc/pc/$host/LOG.$DATE"

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

# Email text/message
echo "$client backup $STATUS" > $EMAILMESSAGE
echo "------------------------------------------------" >>$EMAILMESSAGE
echo "Retrieving the last statement from $host LOG file..."
tail -n 2 "$LOG_FILE" >>$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

/usr/sbin/sendmail "$EMAIL" < $EMAILMESSAGE

else
        STATUS="has FAILED"

#If it had failed, send out the error report
# Email text/message
echo "$client backup $STATUS" > $EMAILMESSAGE
echo "---------------------------------" >>$EMAILMESSAGE
echo "Retrieving the last statement from $host LOG file..."
tail -n 2 "$LOG_FILE" >>$EMAILMESSAGE

# send an email using sendmail
/usr/sbin/sendmail "$EMAIL" < $EMAILMESSAGE
fi

And here is my email I got sent:

uklamp01 backup has been SUCCESSFUL
------------------------------------------------
2017-08-25 08:52:31 incr backup started back to 2017-08-15 09:45:02 (backup #0) for directory /
2017-08-25 09:08:41 Output from DumpPostUserCmd: Retrieving the last statement from uklamp01 LOG file...
------------------------------------------------
Type: incr
Client: uklamp01
Host: uklamp01
Host IP: uklamp01
Share: /
XferMethod: rsync
sshPath: /usr/bin/ssh
cmdType: DumpPostUserCmd

And here is the LOG file from BackupcPC's GUI: enter image description here

How is a string("Retrieving the ...etc ") from my script in the actual LOG file in BackupPC? And is there a way to resolve this, please?

  • This is not following of this unix.stackexchange.com/q/387907/72456? – αғsнιη Aug 25 '17 at 9:10
  • You're not redirecting that line, so... don't echo or redirect it. – Mat Aug 25 '17 at 9:15
  • Either don't echo the line or redirect it to /dev/null. – Raman Sailopal Aug 25 '17 at 9:18
  • I totally forgot to redirect that line. Thanks, guys. – Marc Aug 25 '17 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.