shell使用/var/log/messages 信息生成HTML文件
脚本代码如下:
XML/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
chmod a+x mess2htm.awk
./mess2htm.awk message_file >message.html