I am trying to write a shell script which sends the output of df -h
in mail with the help of HTML code embedded in the script. The issue is this is printing all six columns. I want only specific sequence (6,2,3,4,5). How do I achieve it? Tried lots of things putting array also ) but still not working.
#! /bin/bash
[email protected]
HOST=`hostname`
Numberofdays=2
ALERT_DIR_COUNT=`df -Ph | grep -v "Use%" | sed 's/%//g' | awk '$5 > 70
{print $1,$2,$3,$4,$5"%",$6;}' | column -t | wc -l`
(
printf "To: [email protected]\n"
printf "Subject:$HOST\n :$ALERT_DIR_COUNT\n mounts reached threshold & Logs
Cleared : $Numberofdays days\n"
printf "Content-Type: text/html\n"
printf "<html>\n
<body>\n"
df -Ph| awk '{ print $6,$2,$3,$4,$5 }''
BEGIN {
print "<table border=\"8\" cellpadding=\"3\" style=\"border-collapse:
collapse\">"
printf "<tr>"
printf "<th bgcolor=turquoise colspan="6">BEFORE_USAGE</th>"
printf "</tr>"
printf "<tr>"
printf "<th bgcolor=gray>MOUNT</th>"
printf "<th bgcolor=gray>SIZE</th>"
printf "<th bgcolor=gray>USED</th>"
printf "<th bgcolor=gray>AVAILABLE</th>"
printf "<th bgcolor=gray>USE%</th>"
printf "</tr>"}
NR>1{
for( i = 1; i <= NF; i++ ) {
printf "%s", "<td bgcolor=azure"
if (i==5&&$i+0>70) printf " bgcolor=azure"
print ">" $i "</td>"
}
print "</tr>"
}
END { print "</table>" }'
:
).) (3) TheBEGIN
block (if any) must be the first thing in anawk
program. (4) Please don’t say'foo''bar'
when you mean'foobar'
unless you have a good reason for doing so (and I can’t think of any). (5) You have an unmatched(
in your script (beforeprintf "To: [email protected]\n"
). … (Cont’d)bgcolor=azure
unconditionally (for every cell/value), and then, conditionally, again. (8) Your script is very complicated. Simplify it, get something working, and then build on it.