我有一個循環,隨着它的增長,它將跟隨一個日誌文件,尋找一個模式並對其作出反應。問題是我在某個地方打了一個緩衝區,導致輸入循環延遲,我相信這是由於tail -f
和管道日誌到grep
。最大限度地減少在bash中延遲循環處理的緩衝管道
不工作
while read l; do echo "l = |$l|"; done < <(tail -f $logfile | grep $pattern)
我有安裝$logfile
作爲fifo
並具有cat realfile.log > $logfile
3或4倍(realfile.log是〜2K線),緩衝似乎以填充和線之前通過循環立即處理。
如果我從重定向的stdin中刪除grep $pattern
,則按預期處理該文件。
不工作
while read l; do echo "l = |$l|"; done < <(tail -f $logfile)
同樣適用
while read l; do echo "l = |$l|"; done < <(tail $logfile | grep $pattern)
難道tail
不fsync()'ing
上-f
寫操作?
http://stackoverflow.com/questions/972370/how-do-you-pipe-input-通過grep-to-another-utility – Iain
lain,在我的搜索中沒有看到。 – mmlb