將/var/log/messages資訊產生HTML檔案

來源:互聯網
上載者:User

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 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.