[Shell] Shell 生成 HTML指令碼

tolilong發表於2016-03-20
Shell 生成 HTML指令碼
生成的格式不好看,以後要多改進.

[mon@oracle6 source]$ more gen_html 
#!/bin/bash 
datetime=`date +"%Y/%m/%d %H:%M:%S"`
DATA=/home/mon/source/config/mon_host_stat.data
MAILLIST=tolilong@163.com,bruce_lilong@163.com
COUNT=4
MAILLIST=tolilong@163.com
HTMLFILE=/home/mon/data/gen_html.html

echo "<html>" > $HTMLFILE

echo "<body><h2>Ping Report of $datetime</h2>" > $HTMLFILE
echo "<table border=\"1\" bordercolor=\"#000000\" width=\"350\"  style=\"BORDER-COLLAPSE: collapse\" >" >> $HTMLFILE
echo "<tr style=\"color:White\" bgColor=#0066CC><th>IP</th><th>Hostname</th><th>Status</th></tr>" >> $HTMLFILE

cat $DATA | while read LINE
do
   IP=`echo $LINE | awk '{print $1}'`
   HOSTNAME=`echo $LINE | awk '{print $2}'`

   RESULT=`ping $IP -c $COUNT | grep "packet loss" | awk '{print $6}'  | sed 's/%//g'`
   echo "<tr align=\"center\" ><td>$IP</td><td>$HOSTNAME</td><td>$RESULT</td></tr>" >> $HTMLFILE
done

echo "</table></body></html>" >> $HTMLFILE
cat $HTMLFILE | mutt -s "Ping Host Check Status" -e  "set content_type=text/html" $MAILLIST  -a $HTMLFILE

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2060410/,如需轉載,請註明出處,否則將追究法律責任。

相關文章