2014-04-30 15 views
7

coda ha le seguenti opzioni:Coda -f + grep?

-f  The -f option causes tail to not stop when end of file is reached, but rather to wait for additional data to be appended to the 
      input. The -f option is ignored if the standard input is a pipe, but not if it is a FIFO. 

mi piacerebbe grep solo per something nell'output coda.

tail -f <FILE> | grep <SOMETHING> 

Il problema è eseguire solo grep una volta ed è terminato. Nessun altro risultato si verifica. Come posso far funzionare grep correttamente con lo -f?

+5

Spesso faccio esattamente quello che stai descrivendo, e funziona. Il comando 'grep' non termina finché il processo' tail -f' non termina, ma ovviamente non produce alcun output fino a quando qualcosa contenente il pattern non viene aggiunto al file. –

+2

Posso confermare lo stesso su diverse piattaforme. Non ho mai avuto problemi nell'usare tail + grep esattamente come descritto qui. Su quale piattaforma hai problemi? –

+1

'Il problema è che esegue grep una volta sola e si fa? No non è giusto. – anubhava

risposta

6

Se questo è un file di registro, potrebbe essere ruotato. Quindi smetterà di dare dati.
Questo non si fermerà se il file viene ruotato.

tail --follow=name /var/log/syslog | grep "some data"