Problem extracting 2nd line of log file in bash

52 Views Asked by At

I have the below script which i want to use to send me email if a backup has been completed. All works fine and i get the email but for some reason i have a problem getting the 2nd line of the log file which i am trying to set as the Subject line. In the sample the 2nd line is

Backup successfully completed

but instead of showing this as subject in my message i get only Backup and then the email also gets send to successfully and completed. So not sure what causes this .

#!/bin/bash

#Specify Base Dir for Log
MYPATH="/home/log"

#Create Variable MYFile with current Date
MYFILE=$MYPATH/backupcron-$(date +\%Y-\%m-\%d_\%H:\%M:\%S).log

#Backup Cluster
/opt/couchbase/bin/cbbackupmgr backup -c 127.0.0.1 -u Administrator -p Password -a /media/backup/couch -r CMR-CRM > $MYFILE

# Read the File into STR
STR=$(cat $MYFILE)

#Get the 2nd Line of Log File as Subject
SUBJECT=$(sed -n '2p' < $MYFILE)

# Send Email via Mutt
echo "$STR" | mutt -s $SUBJECT -a $MYFILE -e 'my_hdr From:COUCHBACKUP <couchbase@intra>' -- [email protected]

Here is what the Log file looks like which i try to get 2nd line from

Warning: Progress bar disabled because terminal width is less than 80 characters
Backup successfully completed
Backed up bucket "Contacts" succeeded
Mutations backed up: 0, Mutations failed to backup: 0
Deletions backed up: 0, Deletions failed to backup: 0
Skipped due to purge number or conflict resolution: Mutations: 0 Deletions: 0
Backed up bucket "SOAPAPI" succeeded
Mutations backed up: 0, Mutations failed to backup: 0
Deletions backed up: 0, Deletions failed to backup: 0
Skipped due to purge number or conflict resolution: Mutations: 0 Deletions: 0
Backed up bucket "default" succeeded
Mutations backed up: 0, Mutations failed to backup: 0
Deletions backed up: 0, Deletions failed to backup: 0
Skipped due to purge number or conflict resolution: Mutations: 0 Deletions: 0
Backed up bucket "mail_store" succeeded
Mutations backed up: 18, Mutations failed to backup: 0
Deletions backed up: 0, Deletions failed to backup: 0
Skipped due to purge number or conflict resolution: Mutations: 0 Deletions: 0
Backed up bucket "mls" succeeded
Mutations backed up: 0, Mutations failed to backup: 0
Deletions backed up: 0, Deletions failed to backup: 0
Skipped due to purge number or conflict resolution: Mutations: 0 Deletions: 0
Backed up bucket "rets" succeeded
Mutations backed up: 6042, Mutations failed to backup: 0
Deletions backed up: 0, Deletions failed to backup: 0
Skipped due to purge number or conflict resolution: Mutations: 0 Deletions: 0
Backed up bucket "vodex" succeeded
Mutations backed up: 0, Mutations failed to backup: 0
Deletions backed up: 0, Deletions failed to backup: 0
Skipped due to purge number or conflict resolution: Mutations: 0 Deletions: 0
0

There are 0 best solutions below