Why aren’t new string characters saved in the above letter?
#!/bin/bash
file="/tmp/ip.txt"
address=$(curl -s http://ipecho.net/plain; echo)
ifconfig=$(ifconfig)
function build_body
{
echo "----------------------------------------------------------------" > $file
echo "IP Address: $address (according to http://ipecho.net/plain)" >> $file
echo "----------------------------------------------------------------" >> $file
echo >> $file
echo "Result from ifconfig:" >> $file
echo >> $file
echo "$ifconfig" >> $file
echo >> $file
}
build_body
msg=$(cat $file)
mail="subject:Home Server Status\nfrom:email@example.com\n$msg"
echo $mail | /usr/sbin/sendmail "email2@example.com"
I get the email that the script generates, but the whole body is on the same line! /tmp/ip.txt is exactly how I want the email to look.
source
share