Yes. But we need more information.
With this latest version of your script we know that the text being sent is correctly formatted and that your recipient's mail reader is reformatting the text in the message before displaying it.
What application is being used by abc@gmail.com to read mail?
It uses MS Outlook,
If the mail reader being used is expecting HTML input, the thread Sendmail ignoring line endings
might provide the information we need to work around your problem by changing the line:
Yeah, I've gone through the thread Sendmail ignoring line endings and found that
The only one NOT adhering to this convention is perhaps your mail reader program (more correctly: mail user agent), which is probably Microsoft Outlook or similar crap. Because against all convention, laid down in RFCs, M$$ once decreed that email is not any longer plain ASCII text by default with MIME-parts in HTML being allowed, but in fact email is HTML from the start (to be precise: not exactly HTML, but what M$$ took as being being HTML, which wasn't quite up to the standard either).
then I tried with your script,
Code:
printf '%s\n' "${alertlist[@]}" | mail -s "ALERT: Running out of space" $maillist;
to something like:
Code:
{ echo '<HTML><BODY>'
printf '%s<br />\n' "${alertlist[@]}"
echo '</HTML></BODY>'
} | mail -s "ALERT: Running out of space" $maillist;
This is my updated script part
if [ ${#alertlist} -gt 0 ]; then
#printf '%s\n' "${alertlist[@]}" | mail -s "ALERT: Running out of space" $maillist;
{
printf '%s' "${alertlist[@]}\n"
} | mail -s "ALERT: Running out of space" $maillist;
echo "Following text sent as body of mail to $maillist:"
printf '%s\n' "${alertlist[@]}"
fi #alertlist holds the values to send mail.
I removed
echo '<HTML><BODY>'
Because it prints in mail,
the output is
<HTML><BODY>
Running out of space "/u02 (94%)" on localhost.local as on Wed May 17 <br />Running out of space "/u05 (99%)" on localhost.local as on Wed May 17<br /></HTML></BODY>
am using MS Outlook 2013, what it does seems it prints all the line along <HTML>
---------- Post updated at 11:00 PM ---------- Previous update was at 10:58 PM ----------
export maillist=abc@gmail.com;
#df -PH /d04 /d05 /u01 /export | grep -vE '^Filesystem|none|cdrom'|awk '{ print $5 " " $6 }' | while read output;
df -PH | grep -vE '^Filesystem|none|cdrom|swdepot'|awk '{ print $5 " " $6 }' > $HOME/monitor/diskcheck.log;
unset usep usep1
declare -A usep usep1
if [ -s "$HOME/monitor/log/disk_alert.log" ]; then
#Getting variables and compare with old
while read -r pct fs
do pct=${pct%\%}
usep["$fs"]=$pct
printf '%s(%s) ' "$fs" "$pct"
done < "$HOME/monitor/diskcheck.log"
echo
while read -r pct fs
do pct=${pct%\%}
usep1["$fs"]=$pct
printf '%s(%s) ' "$fs" "$pct"
done < "$HOME/monitor/log/disk_alert.log"
echo
else
cp "$HOME/monitor/diskcheck.log" "$HOME/monitor/log/disk_alert.log"
# Note that if disckcheck.log and disk_alert.log are identical, usep[$i] can
# never be greater than usep1[$i], so we might as well quit now.
exit
fi
unset alertlist
for fs in ${!usep[@]}; do
if [ ${usep["$fs"]} -gt 80 ]; then
if [ ${usep["$fs"]} -gt ${usep1["$fs"]} ]; then
# Temp to store current percentage diff and partition to store in a variable.
tmp="$(echo -e "Running out of space \"$i (${usep["$fs"]}%%)\" on $(hostname) as on $(date)")";
echo "$tmp"
#tmp=$(printf "%s\n" "(${usep["$fs"]}%%) percent used on $i");
alertlist=("${alertlist[@]}" "$tmp")
fi
fi
done
if [ ${#alertlist} -gt 0 ]; then
{ echo '<HTML><BODY>'
printf '%s<br />\n' "${alertlist[@]}"
echo '</HTML></BODY>'
} | mail -s "ALERT: Running out of space" $maillist
echo "Following text sent as body of mail to $maillist:"
printf '%s\n' "${alertlist[@]}"
fi
Thank you so much for sharing this kinda stuff, I would go implement this thing once the mailing part is succeed.