I want to use a bash script to run a backup and then send me an email using ssmtp. I am trying to make a generic script that I can reuse across different Linux machines. Below is a snippet of the script where I use sed to replace some placeholder text with $HOSTNAME
and $DATE
variables. For some reason when it's run, I get the email but instead of inserting the hostname and date, it wipes out the placeholders. Can someone point out what I'm doing wrong?
Here's the section of my script:
sed -i -e "s/HNAME/$HOSTNAME/g" backup_notification
sed -i -e "s/DATETIME/$date/g" backup_notification
ssmtp [email protected] < backup_notification
Here's the text file of the notification (HNAME
and DATETIME
are the placeholders I want sed to replace with system variable information):
To: [email protected]
From: [email protected]
Subject: Backup completed
This confirms that backup is completed for HNAME on DATETIME.
And here's what the text of the email has (notice that the HNAME and DATETIME placeholders were wiped or replaced with nil.):
-----Original Message-----
From: root [mailto:[email protected]]
Sent: Thursday, March 10, 2016 1:15 PM
To: Me
Subject: Backup completed
This confirms that the backup is completed for has been renewed on .
TIA for any help :)!