• 将/var/log/messages信息生成HTML文件


    shell使用/var/log/messages 信息生成HTML文件

    脚本代码如下:

    XML/HTML代码
    1. #!/bin/awk -f   
    2.   
    3. BEGIN {   
    4.         # 定义每个颜色区域的开始字段及其颜色,以下表示的意思是 1-3 是red, 4-5是yellow, 6-末尾是blue   
    5.         ffmt = "1,4,6";   
    6.         cfmt = "red,yellow,blue";   
    7.   
    8.         split(ffmt, field, ",");   
    9.         split(cfmt, color, ",");   
    10.   
    11.         print "<html>";   
    12.         print "<head><title> message </title></head>";   
    13.         print "<body>";   
    14.         print "<table border=0>";   
    15. }   
    16.   
    17. {   
    18.         print "<tr>";   
    19.   
    20.         m = 1;   
    21.         for (i=1; i<=NF; i++) {   
    22.                 if (i == field[m]) {   
    23.                         if (i != field[1]) print "</font></td>";   
    24.                         printf "<td><font color=" color[m] ">";   
    25.                         m++;   
    26.                 }   
    27.                 printf "%s ", $i;   
    28.         }   
    29.         print "</font></td>";   
    30.   
    31.         print "</tr>";   
    32. }   
    33.   
    34. END {   
    35.         print "</table>";   
    36.         print "</body>";   
    37.         print "</html>";   
    38. }   
    以上代码保存成 mess2htm.awk
    chmod a+x mess2htm.awk
    ./mess2htm.awk message_file  >message.html
     
  • 相关阅读:
    正则表达式
    js trim函数 去空格函数与正则集锦
    变量的作用域问题
    for...in 语句
    JS小案例分析
    JS动态创建元素的方式
    JS类的封装
    js操作节点小结
    节点兼容
    节点小结
  • 原文地址:https://www.cnblogs.com/studio313/p/2870330.html
Copyright © 2020-2023  润新知