I would like to extract the last line of the log in BackupPC, so if a failed backup occurs, I will know why by the email. I have used the commandsed to get the last line of the log. However, I'm having difficulties echoing that out to the screen. It's showing the FAILED line, but not the error line from the log. How can I fix this, and/or is there a better way to do this?#!/bin/bash# script to send simple email# Email To ?EMAIL=myemail@mydomain.com# Email text/messageEMAILMESSAGE=/var/lib/backuppc/emailmessage.txt#Extract the last line of the log for error reportingLOG_FILE=/var/lib/backuppc/log/LOG #Grab the status variablesxferOK=$1host=$2type=$3client=$4hostIP=$5share=$6XferMethod=$7sshPath=$8cmdType=$9# Check if backup succeeded or not.if [[ $xferOK == 1 ]]; then        STATUS=has been SUCCESSFUL# Email text/messageecho $client backup $STATUS > $EMAILMESSAGEecho ------------------------------------------------------ >>$EMAILMESSAGEecho Type: $type >>$EMAILMESSAGEecho Client: $client >>$EMAILMESSAGEecho Host: $host >>$EMAILMESSAGEecho Host IP: $hostIP >>$EMAILMESSAGEecho Share: $share >>$EMAILMESSAGEecho XferMethod: $XferMethod >>$EMAILMESSAGEecho sshPath: $sshPath >>$EMAILMESSAGEecho cmdType: $cmdType >>$EMAILMESSAGE/usr/sbin/sendmail $EMAIL < $EMAILMESSAGEelse        STATUS=has FAILED#If it had failed, send out the error report# Email text/messageecho $client backup $STATUS > $EMAILMESSAGEecho --------------------------------- >>$EMAILMESSAGEecho $LOG_FILE | sed -n '$p' >>$EMAILMESSAGE/usr/sbin/sendmail $EMAIL < $EMAILMESSAGEThe output from my emails. No line from the LOG file whatsoever. ukat2 backup has FAILED---------------------------------
Using sed in echo command for bash script
linux;bash;shell script;sed