【问题标题】:Grab results from one query and put it in another (searching mx records)从一个查询中获取结果并将其放入另一个查询中(搜索 mx 记录)
【发布时间】:2012-07-17 15:24:16
【问题描述】:

我有很多电子邮件日志文件要查看。我正在尝试查找我们发送给的每个人,按 mx 服务器排序。

这将返回 MX 服务器列表:

grep 'mx' /my/log/file | cut -d , -f 11 | cut -d ' ' -f 1 | sort | uniq

Ex 输出:

mx3.hotmail.com
mx2.hotmail.com
mx1.hotmail.com
mx4.hotmail.com

这会抓取从该 MX 服务器发送到的域(在本例中为所有 hotmail):

grep 'mx*.hotmail.com' /my/log/file | cut -d , -f 6 | cut -d '@' -f 2 | sort | uniq

Ex 输出:

hotmail.com
hotmail.com.au

如何编写脚本以便将一个查询的结果直接插入另一个查询?我把python作为标签是因为我熟悉它。

【问题讨论】:

  • 显示示例日志条目。

标签: python linux grep mx-record


【解决方案1】:

mx*.hotmail.com 应该匹配 m.hotmail.commx.hotmail.commxx.hotmail.com 等。你可能想要mx.*\.hotmail\.com

要在另一个 bash 命令中使用来自一个 bash 命令的字符串,您可以使用 $()。例如。 echo abc$(echo def)ghi

您也可以使用反引号,但反引号也不能嵌套。

【讨论】:

    【解决方案2】:

    这就是我们最终要做的:

    cat /my/log/file | cut -d "," -f 11,6 | cut -d '@' -f 2 | cut -d ' ' -f 1 | egrep '(([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}),(([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6})' | cut -d "," -f 2,1 | sort | uniq > /tmp/mxservers2.txt
    

    结果如下:

    hotmail.com,mx1.hotmail.com
    

    作为参考,日志条目如下所示:

    d,2012-07-17 07:09:29+0000,2012-07-17 07:09:15+0000,,bounce@address.net,recipient@example.net,,relayed,2.0.0 (success),smtp;250 2.0.0 bK9F1j04M0vJLGl06K9VnA mail accepted for delivery,mx.example.net (0.0.0.0),,smtp,(127.0.0.1),smtp,sending IP,receiving IP,"ENHANCEDSTATUSCODES,8BITMIME,SIZE,STARTTLS",18704,sending.domain.com,message.streaming,,FALSE,=?utf-8?Q?Subject?= <sender@example2.net>
    

    不完美,但完成了工作。

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2013-03-01
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      • 2016-12-18
      • 2014-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多