将/var/log/messages内容生成html文件的脚本
时间:2014-09-08 22:59 来源:linux.it.net.cn 作者:it
通过shell将/var/log/messages内容生成HTML文件
脚本代码
复制代码代码如下:
#!/bin/awk -f
BEGIN {
# 定义每个颜色区域的开始字段及其颜色,以下表示的意思是 1-3 是red, 4-5是yellow, 6-末尾是blue
ffmt = "1,4,6";
cfmt = "red,yellow,blue";
split(ffmt, field, ",");
split(cfmt, color, ",");
print "<html>";
print "<head><title> message </title></head>";
print "<body>";
print "<table border=0>";
}
{
print "<tr>";
m = 1;
for (i=1; i<=NF; i++) {
if (i == field[m]) {
if (i != field[1]) print "</font></td>";
printf "<td><font color=" color[m] ">";
m++;
}
printf "%s ", $i;
}
print "</font></td>";
print "</tr>";
}
END {
print "</table>";
print "</body>";
print "</html>";
}
将以上代码保存为:mess2htm.awk。
然后增加执行权限:
chmod a+x mess2htm.awk
执行:
./mess2htm.awk message_file >message.html
(责任编辑:IT)
通过shell将/var/log/messages内容生成HTML文件
复制代码代码如下:
#!/bin/awk -f
BEGIN { # 定义每个颜色区域的开始字段及其颜色,以下表示的意思是 1-3 是red, 4-5是yellow, 6-末尾是blue ffmt = "1,4,6"; cfmt = "red,yellow,blue"; split(ffmt, field, ","); split(cfmt, color, ","); print "<html>"; print "<head><title> message </title></head>"; print "<body>"; print "<table border=0>"; } { print "<tr>"; m = 1; for (i=1; i<=NF; i++) { if (i == field[m]) { if (i != field[1]) print "</font></td>"; printf "<td><font color=" color[m] ">"; m++; } printf "%s ", $i; } print "</font></td>"; print "</tr>"; } END { print "</table>"; print "</body>"; print "</html>"; }
将以上代码保存为:mess2htm.awk。 |