2012-07-17 35 views
0

我有很多電子郵件日誌文件需要通過。我試圖找到我們發送給每個人,由mx服務器排序。從一個查詢中獲取結果並將其放入另一個查詢(搜索mx記錄)

這將返回MX服務器的列表:

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

防爆輸出:

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

這抓起,從這個MX服務器發送到(在這種情況下,區,其中所有的hotmails):

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

防爆輸出:

hotmail.com 
hotmail.com.au 

如何編寫腳本以便我可以將一個查詢的結果直接插入另一個查詢中?我把Python作爲標籤,因爲我熟悉它。

+1

顯示樣本日誌條目。 – 2012-07-17 15:35:13

回答

0

mx*.hotmail.com應符合m.hotmail.commx.hotmail.commxx.hotmail.com,等你可能想mx.*\.hotmail\.com

要使用一個字符串從一個bash命令另外,你可以使用$()。例如。 echo abc$(echo def)ghi

您也可以使用反引號,但反引號不會嵌套。

0

這是我們落得這樣做:

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,,[email protected],[email protected],,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?= <[email protected]> 

不完美,但完成了工作。

相關問題