2016-11-07 85 views
2

我使用varnishlog命令,並試圖篩選某些字段:如果我用另一個grep命令我得到空的結果使用兩個管道給空結果

sudo varnishlog -c | grep -E 'ReqURL|Varnish-Cache' 

- ReqURL   /sample/2 
- RespHeader  X-Varnish-Cache: HIT 
- ReqURL   /sample/2 
- RespHeader  X-Varnish-Cache: HIT 

現在:

sudo varnishlog -c | grep -E 'ReqURL|Varnish-Cache' | grep 'HIT' 

能否請您幫助我在這裏可能是什麼問題?該命令的

示例輸出:sudo varnishlog -c

* <<Request>> 658516 
- Begin   req 658515 rxreq 
- Timestamp  Start: 1478508065.780332 0.000000 0.000000 
- Timestamp  Req: 1478508065.780332 0.000000 0.000000 
- ReqStart  10.56.36.2 55578 
- ReqMethod  GET 
- ReqURL   /sample/2 
- ReqProtocol HTTP/1.1 
- ReqHeader  Host: localhost:6081 
- ReqHeader  User-Agent: Mozilla/5.0 Firefox/44.0 
- ReqHeader  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
- ReqHeader  Accept-Language: en-US,en;q=0.5 
- ReqHeader  Accept-Encoding: gzip, deflate 
- ReqHeader  Connection: keep-alive 
- ReqHeader  Pragma: no-cache 
- ReqHeader  Cache-Control: no-cache 
- VCL_call  RECV 
- VCL_return  hash 
- ReqUnset  Accept-Encoding: gzip, deflate 
- ReqHeader  Accept-Encoding: gzip 
- VCL_call  HASH 
- VCL_return  lookup 
- Hit   658416 
- VCL_call  HIT 
- VCL_return  deliver 
- RespProtocol HTTP/1.1 
- RespStatus  200 
- RespReason  OK 
- RespHeader  Content-Length: 4774 
- RespHeader  Last-Modified: Tue, 12 Apr 2016 17:42:58 GMT 
- RespHeader  Etag: f9d34a65e8c1b30245c2f12534348ff9 
- RespHeader  X-Timestamp: 1460482977.61998 
- RespHeader  Content-Type: image/png 
- RespHeader  X-Trans-Id: txf52283ea65004e578ddfe-0058203d84 
- RespHeader  Date: Mon, 07 Nov 2016 08:38:28 GMT 
- RespHeader  X-Varnish: 658516 658416 
- RespHeader  Age: 157 
- RespHeader  Via: 1.1 varnish-v4 
- VCL_call  DELIVER 
- RespHeader  X-Varnish-Cache: HIT 
- VCL_return  deliver 
- Timestamp  Process: 1478508065.780379 0.000047 0.000047 
- RespHeader  Accept-Ranges: bytes 
- Debug   "RES_MODE 2" 
- RespHeader  Connection: keep-alive 
- Timestamp  Resp: 1478508065.780411 0.000079 0.000032 
- ReqAcct  415 0 415 393 4774 5167 
+0

嘗試將第一個grep模式包裝到括號中。像這樣:'(ReqURL | Varnish-Cache)'。也UNIX版本和varnishlog -c輸出的一部分將是非常有幫助 – sotona

+0

你可以嘗試-u無緩衝輸出。像varnishlog -cu ... –

+0

@sotona,我試過使用括號,但同樣的問題。我用命令的輸出樣本更新了我的帖子。 – user3181365

回答

3

可以使用與如下面的grep --line緩衝選項;

sudo varnishlog -c | grep --line-buffered -E 'ReqURL|Varnish-Cache' | grep --line-buffered 'HIT' 

man grep;

- 行緩衝 對輸出使用行緩衝。這可能會導致性能損失。

+0

你可以請檢查我的其他帖子 - http://stackoverflow.com/questions/40462153/grep-multiple-strings-and-then-replace-text答案是由伊恩給出的,有類似的問題,但使用的命令有' awk'和'sed'與wile循環 – user3181365

相關問題