码迷,mamicode.com
首页 > Web开发 > 详细

SHELL 生成HTML

时间:2016-07-24 00:25:50      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

#!/bin/bash
# 演示使用 shell 脚本创建 HTML 报告的示例脚本
# Web directory
WEB_DIR=/var/www/html
# A little CSS and table layout to make the report look a little nicer
echo "<HTML>
<HEAD>
<style>
.titulo{font-size: 1em; color: white; background:#0863CE; padding: 0.1em 0.2em;}
table
{
border-collapse:collapse;
}
table, td, th
{
border:1px solid black;
}
html{text-align:center;}
</style>
<meta http-equiv=‘Content-Type‘ content=‘text/html; charset=UTF-8‘ />
</HEAD>
<BODY align=center>" > $WEB_DIR/report.html
# View hostname and insert it at the top of the html body
HOST=$(hostname)
echo "Filesystem usage for host <strong>$HOST</strong><br>
Last updated: <strong>$(date)</strong><br><br>


<table border=‘1‘>
<tr>
<th class=‘titulo‘> HOSTNAME</td>
<th class=‘titulo‘>IP</td>
</tr>" >> $WEB_DIR/report.html
#获取IP
ifconfig|grep "inet addr:"|while read line; do
echo "<tr><td align=‘center‘>" >> $WEB_DIR/report.html
echo $HOST >> $WEB_DIR/report.html
echo "</td><td align=‘center‘>" >> $WEB_DIR/report.html
echo $line | awk -F ‘:‘ ‘{print $2}‘| awk -F‘ ‘ ‘{print $1}‘ >> $WEB_DIR/report.html
echo "</td></tr>" >> $WEB_DIR/report.html
done
echo "</table>

<br>
<br>

<table border=‘1‘>
<tr>
<th class=‘titulo‘> Machine Info</td>
<th class=‘titulo‘>Value</td>
</tr>" >> $WEB_DIR/report.html
#获取机器SN号
dmidecode -t 1|egrep -e "Product|Serial"|while read line; do
echo "<tr><td align=‘center‘>" >> $WEB_DIR/report.html
echo $line | awk -F ‘:‘ ‘{print $1}‘ >> $WEB_DIR/report.html
echo "</td><td align=‘center‘>" >> $WEB_DIR/report.html
echo $line | awk -F ‘:‘ ‘{print $2}‘ >> $WEB_DIR/report.html
echo "</td></tr>" >> $WEB_DIR/report.html
done
echo "</table>

<br><br>
<table border=‘1‘>
<tr><th class=‘titulo‘>Filesystem</td>
<th class=‘titulo‘>Size</td>
<th class=‘titulo‘>Use %</td>
</tr>" >> $WEB_DIR/report.html
# 获取硬盘使用情况
df -Ph | grep -vi 文件系统|while read line; do
echo "<tr><td align=‘center‘>" >> $WEB_DIR/report.html
echo $line | awk ‘{print $1}‘ >> $WEB_DIR/report.html
echo "</td><td align=‘center‘>" >> $WEB_DIR/report.html
echo $line | awk ‘{print $2}‘ >> $WEB_DIR/report.html
echo "</td><td align=‘center‘>" >> $WEB_DIR/report.html
echo $line | awk ‘{print $5}‘ >> $WEB_DIR/report.html
echo "</td></tr>" >> $WEB_DIR/report.html
done
echo "</table></BODY></HTML>" >> $WEB_DIR/report.html

技术分享

SHELL 生成HTML

标签:

原文地址:http://www.cnblogs.com/houzhiqing/p/5699742.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!