Script to Generate HTML Rpt
#!/bin/ksh
TODAY=`date +'%Y %b %d'`
rm file.csv
rm report.html
#Hive Query to Fetch Results from Hive Table
hive -S -e "SELECT COLA,COLB FROM hive_tbl;" > file.csv
#Convert the Results to Comma Separated
sed -i 's/\t/,/g' file.csv
#awk command to parse the file
#recCNT=`awk -F ',' '{print $1}' file.csv
#Converting CSV File to HTML
echo "<HTML><BODY>" > report.html
echo "<h2><font color=blue>Report Header</font></h2>" >> report.html
#loop through records in CSV and Convert to Table
awk 'BEGIN{
FS=","
print "<TABLE border="1"><TH><font color=brown><center>
COLA HEADER</center></font></TH><TH><font color=brown><center>COLB HEADER<
/center></font></TH>"}
{
printf "<TR>"
for(i=1;i<=NF;i++)
printf "<TD>%s</TD>", $i
print "</TR>"
}
END{
printf "</TABLE><BODY></HTML>"
}' file.csv >> report.html
#Sending email using mutt command
/usr/bin/mutt -e 'set content_type=text/html' -s "email Subject :$TODAY" email_id1 email_id2 < report.html
#sending email using normal mailx command with attachment
#{
#echo "Hi"
#echo "message"
#} | mailx -s "Subject:" -a report.html email_id1,email_id2
*****************************************************************************
#Report to Generate Header with Background Color and Font
#!/bin/ksh
TODAY=`date +'%Y %b %d'`
rm file.csv
rm report.html
#Hive Query to Fetch Results from Hive Table
hive -S -e "SELECT COLA,COLB FROM hive_tbl;" > file.csv
#Convert the Results to Comma Separated
sed -i 's/\t/,/g' file.csv
#awk command to parse the file
#recCNT=`awk -F ',' '{print $1}' file.csv
#Converting CSV File to HTML
echo "<HTML><HEAD>" > report.html
echo "<style>
.myTable {
width: 100%;
text-align: left;
background-color: white;
border-collapse: collapse;
}
.myTable th {
background-color: yellowgreen;
color: white;
}
.myTable td,
.myTable th {
padding: 10px;
border: 1px solid black;
}
</style>
</HEAD>
<BODY>" >> report.html
echo "<h2><font color=blue>Report Header</font></h2>" >> report.html
#loop through records in CSV and Convert to Table
awk 'BEGIN{
FS=","
print "<TABLE class='myTable'><TR><TH>COLA HEADER</TH><TH>COLB HEADER</TH></TR>"
}
{
printf "<TR>"
for(i=1;i<=NF;i++)
printf "<TD>%s</TD>", $i
print "</TR>"
}
END{
printf "</TABLE><BODY></HTML>"
}' file.csv >> report.html
#Sending email using mutt command
/usr/bin/mutt -e 'set content_type=text/html' -s "email Subject :$TODAY" email_id1 email_id2 < report.html
#sending email using normal mailx command with attachment
#{
#echo "Hi"
#echo "message"
#} | mailx -s "Subject:" -a report.html email_id1,email_id2
#Note: Use https://www.quackit.com/html/codes/tables/html_table_background_color.cfm for Checking the Styles
#in CSS
*****************************************************************************
Comments
Post a Comment