Hi,
I was trying to write a shell script which reads csv file and sends mail in html format along with tables. Hope i have completed 1st part , but while sending mail i was trying to highlight some rows in the table based on the egrep outcome. If the string exists in line/INPUT, i am trying to highlight it(row) with a different color. Tried if else condition with wc -l . but it didn't work. Below is my script . Please correct the script where i am doing wrong. Thanks in advance
#!/bin/sh
(
echo "To: MyMail@domain.com"
echo "Subject: Test HTML"
echo "Content-Type: text/html"
echo
echo "<html> <font face='verdana' size='7' >"
echo "<table border='1' width='100%' bgcolor='#DDDDDD' >" ;
while read INPUT ;
do
b=$? echo "$line" | egrep "Failed|Absent" | wc -l
if [[ $b==0 ]]
then
echo "<tr><td >${INPUT//,/</td><td>}</td></tr>"
else
echo "<tr><td bgcolor='red' >${INPUT//,/</td><td bgcolor='red'>}</td></tr>"
fi ; done < file.csv ; echo "</table>"
echo "</font></html>"
) | /usr/sbin/sendmail -t
Removing if else part , works fine and which completes my 1st part.
b=$? echo "$line" | egrep "Failed|Absent" | wc -l
if [[ $b==0 ]]
then
echo "<tr><td >${INPUT//,/</td><td>}</td></tr>"else
echo "<tr><td bgcolor='red' >${INPUT//,/</td><td bgcolor='red'>}</td></tr>"
fi
Sample of file.csv
Student1,Subject1,Passed,2013-04-27,18:00:00
Student2,Subject2,Failed,2013-04-27,18:00:00
Student3,Subject3,Absent,2013-04-27,18:00:00
Student4,Subject4,In Progress,2013-04-27,18:00:00
Student5,Subject5,Failed,2013-04-27,18:00:00