2012-10-26 43 views
0

我想有/var/log/apache2/access.log的實時複製,所以我可以grep,做主機名解析等grepping數據阿帕奇access.log的

什麼是做的最好的方法這個?

我很好奇,看看有什麼樣的流量是由

+1

你想去哪兒有這樣的實時副本,你要訪問它是如何做,如果你只是想在一個終端? ,使用'tail -f' –

回答

0

通過這樣做:

#Customize as appropriate: 
tail -f /var/log/apache2/access.log | cut -f 0 -d ' ' & 
tail -f /var/log/apache2/access.log | grep foo & 
1

,你可以:

  1. 配置Apache以通過syslog日誌發送,比配置syslog獲取分離的日誌文件(與特定的所有者)。看一看:O'Reilly : Sending Apache httpd Logs to Syslog
  2. 使用tail -f命令,但你必須保證以下命令緩衝,以讀取事件立即

    tail -f /var/log/apache2/access.log | grep --line-buffered "something"

    tail -f /var/log/apache2/access.log | sed -une "/something/p"

  3. 充分利用tail -f | grep使用perl或python(perl是在日誌文件中進行grepping的好選擇)。

(該樣品是從人perlfaq5複製:

for (;;) { 
    for ($curpos = tell(GWFILE); <GWFILE>; $curpos = tell(GWFILE)) { 
       # search for some stuff and put it into files 
    } 
    # sleep for a while 
     seek(GWFILE, $curpos, 0); # seek to where we had been 
}