쉘 스크립트로 만든 report를 html 형태로 생성하는 코드
친구 요청으로 급하게 만든 스크립트
내용은 df -Pi 로 출력되는 내용을 웹상에서 볼수 있게 html 로 생성하는 내용
흔히 쉘 스크립트 상에서 txt 형태로 파일을 생성해 두고 이것을 웹 형태로 report 를 제작할 필요가
있을때 이용하면 좋을듯.. 이런게 필요할 때가 가끔 있는데 그다지 기록해 두지 않아 그때 마다 새로
만드는거 같아..이번엔 기록해 둠..
#!/bin/sh
df -Pi > /tmp/disk_stats.tmp
PNUM=`cat /tmp/disk_stats.tmp | wc -l`
HOSTN=`hostname`
cat <<make_scripts > /tmp/${HOSTN}_disk_usage.html
<html>
<head>
<title>${HOSTN} DISK Partition Usage Infomation</title>
<style type=text/css>
<!–
@font-face {font-family:티티체; src:url(http://syszone.co.kr/fonts/TTche.eot);}
body {font-family:티티체;font-size:9pt;line-height:160%;}
h1 {font-family:티티체;font-size:9pt;line-height:160%;}
td {font-family:티티체;font-size:9pt;line-height:160%;}
th {font-family:티티체;font-size:9pt;line-height:160%;}
a {font-family:티티체;color:darkblue;font-size:9pt;text-decoration:none;}
a:hover {font-family:티티체;color:#FCD251;font-size:9pt;text-decoration:none;}
input { font-family:티티체;font-size:9pt; border:solid 1px #cccccc; padding:1px;height:20px;}
–>
table.type03 {
border-collapse: collapse;
text-align: left;
line-height: 1.5;
border-top: 1px solid #ccc;
border-left: 3px solid #369;
margin : 20px 10px;
}
table.type03 th {
width: 147px;
padding: 10px;
font-weight: bold;
vertical-align: top;
text-align: left;
color: #153d73;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
}
table.type03 td {
width: 349px;
padding: 10px;
vertical-align: top;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
}
</style>
</head>
<body>
<table width=90% border=1 class=type03>
<tr><th colspan=6>* ${HOSTN}’s Disk Inode Usage Infomation</td></tr>
<tr bgcolor=#299CD0>
<th>Filesystem</td>
<th>Inodes</td>
<th>IUsed</td>
<th>IFree</td>
<th>IUse%</td>
<th>Mounted on</td>
</tr>
make_scripts
PNUM_INT=2
while :
do
if [ $PNUM_INT -le $PNUM ] ; then
D_1S=`sed -n “${PNUM_INT}p” /tmp/disk_stats.tmp | awk ‘{print $1}’`
D_2S=`sed -n “${PNUM_INT}p” /tmp/disk_stats.tmp | awk ‘{print $2}’`
D_3S=`sed -n “${PNUM_INT}p” /tmp/disk_stats.tmp | awk ‘{print $3}’`
D_4S=`sed -n “${PNUM_INT}p” /tmp/disk_stats.tmp | awk ‘{print $4}’`
D_5S=`sed -n “${PNUM_INT}p” /tmp/disk_stats.tmp | awk ‘{print $5}’`
D_6S=`sed -n “${PNUM_INT}p” /tmp/disk_stats.tmp | awk ‘{print $6,$7}’`
D_5SS=`sed -n “${PNUM_INT}p” /tmp/disk_stats.tmp | awk ‘{print $5}’ | sed -e “s/%//g”`
if [ $D_5SS -gt 1 ] ; then
cat <<make_scripts >> /tmp/${HOSTN}_disk_usage.html
<tr bgcolor=#FF7468>
<th scope=row>$D_1S</td>
<td>$D_2S</td>
<td>$D_3S</td>
<td>$D_4S</td>
<td>$D_5S</td>
<td>$D_6S</td>
</tr>
make_scripts
else
cat <<make_scripts >> /tmp/${HOSTN}_disk_usage.html
<tr bgcolor=#F0E9E9>
<td scope=row>$D_1S</td>
<td>$D_2S</td>
<td>$D_3S</td>
<td>$D_4S</td>
<td>$D_5S</td>
<td>$D_6S</td>
</tr>
make_scripts
fi
else
break
fi
PNUM_INT=`expr $PNUM_INT + 1`
done
cat <<make_scripts >> /tmp/${HOSTN}_disk_usage.html
</table>
</body>
</html>
make_scripts
2 Responses
… [Trackback]
[…] Find More Information here to that Topic: nblog.syszone.co.kr/archives/8063 […]
… [Trackback]
[…] There you will find 72315 more Info to that Topic: nblog.syszone.co.kr/archives/8063 […]