在Ubuntu上解析病毒扫描结果

时间:2019-05-04 22:54:01

标签: bash parsing awk sed grep

我正在尝试在Ubuntu上解析病毒扫描结果。命令行:

root@pc:/bin# /opt/eset/esets/sbin/esets_scan --clean-mode=None /home/majid/Bureau/1.exe

ESET Command-line scanner, version 4.0.93, (C) 1992-2013 ESET, spol. s r.o.
Module loader, version 1072 (20180813), build 1118
Module perseus, version 1549.3 (20190326), build 2010
Module scanner, version 19107 (20190329), build 40871
Module archiver, version 1285 (20190313), build 1377
Module advheur, version 1192 (20190204), build 1173
Module cleaner, version 1183 (20190305), build 1269

Command line: --clean-mode=None /home/majid/Bureau/1.exe 

Scan started at:   dim. 05 mai 2019 00:52:01 CEST
name="/home/majid/Bureau/1.exe", threat="a variant of MSIL/Kryptik.QME trojan", action="", info=""

Scan completed at: dim. 05 mai 2019 00:52:01 CEST
Scan time:         0 sec (0:00:00)
Total:             files - 1, objects 1
Infected:          files - 1, objects 1
Cleaned:           files - 0, objects 0

我想要什么?检查是否存在threat=xxxxx,如果是,则仅返回类似a variant of MSIL/Kryptik.QME trojan的类型,否则返回clean

2 个答案:

答案 0 :(得分:1)

使用GNU grep,您可以执行以下操作:

/opt/eset/esets/sbin/esets_scan --clean-mode=None /home/majid/Bureau/1.exe |
  grep -Po 'threat="\K[^"]*' || echo clean

如果一行包含threat=",则它将输出所有内容,直到下一个双引号为止。否则,它将打印clean

请注意,如果您的病毒扫描程序由于某种原因失败,则上述命令仍然会说clean,如果有问题请发表评论。

答案 1 :(得分:0)

使用GNU awk匹配的第三个参数:

$ awk 'BEGIN{t="clean"} match($0,/threat="([^"]+)/,a){t=a[1]; exit} END{print t}' file
a variant of MSIL/Kryptik.QME trojan

在任何UNIX框中的任何shell中使用任何awk:

$ awk 'BEGIN{t="clean"} match($0,/threat="[^"]+/){t=substr($0,RSTART+8,RLENGTH-8); exit} END{print t}' file
a variant of MSIL/Kryptik.QME trojan