如何通过awk命令实现着色并通过邮件发送?
How to implement coloring through awk command and send it via mail?
我正在尝试将 .txt 文件转换为 .html 文件以供着色并通过邮件发送。
我得到正确的着色,直到 "MQ-FEEDs:" 如下例所述。
但其余选定的案例打印了两次,第二次是彩色的(例如:FAILED FAILED(红色)),你能帮我解决这个问题吗,非常感谢!
我得到的输出:
举报:
|DATE | FEED NAMEs AS OF NOW | AVG_TIME| ARR_TIME |SIZE(MB)|COUNT|STATUS |
Jan 6 CHCK09_20170106.txt 20:46 21:15 0.180 1430 DELAYED
Jan 6 EGLOUT_xml_20170106.txt 15:46 15:46 0.008 247 On_Time
Jan 9 MTS_SOD_20170106.TXT 07:05 00:06 4.005 1 No_Records
MQ-FEEDs:
Jan 09 03:39 MTS_TRANSACTION_FEED MQ 1 3719238761373 SUCCESS SUCCESS
Jan 09 03:37 HOGAN_TRANSACTION_FEED MQ 1 3719235506904 FAILED FAILED
MANUAL-UPLOAD-FEEDs: MANUAL-UPLOAD-FEEDs:
DB-POOL-FEEDs: DB-POOL-FEEDs:
NOTE : Feednames starting with PLUS sign(+) indicates they are in INPROGRESS Directory.
DELAYING-FILES-ARE DELAYING-FILES-ARE
代码:
#!/bin/ksh
export PATH1="/auto/users/scripts"
awk 'BEGIN {
print "<html>" \
"<body bgcolor=\"#DEF3F0\" text=\"#003abc\">" \
"<pre>"
}
NR == 0 { print [=11=] }
NR > 0 {
if ($NF == "DELAYED") {color="red"; bold=1; size="15px"; italic=0;}
else if ($NF == "On_Time") {color="green"; bold=1; size="15px"; italic=0;}
else if ($NF == "SUCCESS") {color="green"; bold=1; size="15px"; italic=0;}
else if ($NF == "FAILED") {color="red"; bold=1; size="15px"; italic=0;}
else if ($NF == "MQ-FEEDs:") {color="magenta"; bold=1; size="15px"; italic=0;}
else if ($NF == "MANUAL-UPLOAD-FEEDs:") {color="magenta"; bold=1; size="15px"; italic=0;}
else if ($NF == "DB-POOL-FEEDs:") {color="magenta"; bold=1; size="15px"; italic=0;}
else if ($NF == "No_Records") {color="blueviolet"; bold=0; size="20px"; italic=1;}
else if ($NF == "DELAYING-FILES-ARE") {color="red"; bold=1; size="25px"; italic=0;}
else {color="#003abc"; bold=0; size="25px"; italic=0;}
Dummy=[=11=]
sub("[^ ]+$","",Dummy)
print Dummy "<span style=\"color:" color (bold ? ";font-weight:bold" : "")(size ? ";font-size:size" : "") (italic ? ";font-style:italic" : "") "\">" $NF "</span>"
}
END {
print "</pre>" \
"</body>" \
"</html>"
}
' output.txt > output.html
mail -s "$(echo -e "This is Subject\nContent-Type: text/html")" xyz@email.com < output.html
您只需稍作调整即可使输出翻倍。
LASTFIELD=$NF
Dummy=[=10=]
gsub("[\t ]+$","",Dummy)
gsub("[^ ]+$","",Dummy)
print Dummy"<span style=\"color:" color (bold ? ";font-weight:bold" : "")(size ? ";font-size:size" : "") (italic ? ";font-style:italic" : "") "\">"LASTFIELD"</span>"
我正在尝试将 .txt 文件转换为 .html 文件以供着色并通过邮件发送。 我得到正确的着色,直到 "MQ-FEEDs:" 如下例所述。 但其余选定的案例打印了两次,第二次是彩色的(例如:FAILED FAILED(红色)),你能帮我解决这个问题吗,非常感谢!
我得到的输出:
举报:
|DATE | FEED NAMEs AS OF NOW | AVG_TIME| ARR_TIME |SIZE(MB)|COUNT|STATUS |
Jan 6 CHCK09_20170106.txt 20:46 21:15 0.180 1430 DELAYED
Jan 6 EGLOUT_xml_20170106.txt 15:46 15:46 0.008 247 On_Time
Jan 9 MTS_SOD_20170106.TXT 07:05 00:06 4.005 1 No_Records
MQ-FEEDs:
Jan 09 03:39 MTS_TRANSACTION_FEED MQ 1 3719238761373 SUCCESS SUCCESS
Jan 09 03:37 HOGAN_TRANSACTION_FEED MQ 1 3719235506904 FAILED FAILED
MANUAL-UPLOAD-FEEDs: MANUAL-UPLOAD-FEEDs:
DB-POOL-FEEDs: DB-POOL-FEEDs:
NOTE : Feednames starting with PLUS sign(+) indicates they are in INPROGRESS Directory.
DELAYING-FILES-ARE DELAYING-FILES-ARE
代码:
#!/bin/ksh
export PATH1="/auto/users/scripts"
awk 'BEGIN {
print "<html>" \
"<body bgcolor=\"#DEF3F0\" text=\"#003abc\">" \
"<pre>"
}
NR == 0 { print [=11=] }
NR > 0 {
if ($NF == "DELAYED") {color="red"; bold=1; size="15px"; italic=0;}
else if ($NF == "On_Time") {color="green"; bold=1; size="15px"; italic=0;}
else if ($NF == "SUCCESS") {color="green"; bold=1; size="15px"; italic=0;}
else if ($NF == "FAILED") {color="red"; bold=1; size="15px"; italic=0;}
else if ($NF == "MQ-FEEDs:") {color="magenta"; bold=1; size="15px"; italic=0;}
else if ($NF == "MANUAL-UPLOAD-FEEDs:") {color="magenta"; bold=1; size="15px"; italic=0;}
else if ($NF == "DB-POOL-FEEDs:") {color="magenta"; bold=1; size="15px"; italic=0;}
else if ($NF == "No_Records") {color="blueviolet"; bold=0; size="20px"; italic=1;}
else if ($NF == "DELAYING-FILES-ARE") {color="red"; bold=1; size="25px"; italic=0;}
else {color="#003abc"; bold=0; size="25px"; italic=0;}
Dummy=[=11=]
sub("[^ ]+$","",Dummy)
print Dummy "<span style=\"color:" color (bold ? ";font-weight:bold" : "")(size ? ";font-size:size" : "") (italic ? ";font-style:italic" : "") "\">" $NF "</span>"
}
END {
print "</pre>" \
"</body>" \
"</html>"
}
' output.txt > output.html
mail -s "$(echo -e "This is Subject\nContent-Type: text/html")" xyz@email.com < output.html
您只需稍作调整即可使输出翻倍。
LASTFIELD=$NF
Dummy=[=10=]
gsub("[\t ]+$","",Dummy)
gsub("[^ ]+$","",Dummy)
print Dummy"<span style=\"color:" color (bold ? ";font-weight:bold" : "")(size ? ";font-size:size" : "") (italic ? ";font-style:italic" : "") "\">"LASTFIELD"</span>"