2014-04-30 6 views
7

Schwanz hat folgende Möglichkeiten:Schwanz -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. 

ich nur für something im Heck Ausgabe möchte grep.

tail -f <FILE> | grep <SOMETHING> 

Problem ist es nur laufen grep einmal und fertig ist. Keine andere Ausgabe geschieht. Wie kann ich Grep korrekt mit dem -f laufen lassen?

+5

Ich mache oft genau das, was Sie beschreiben, und es funktioniert. Der 'grep'-Befehl wird nicht beendet, bis der' tail -f'-Prozess endet, aber natürlich erzeugt er keine Ausgabe, bis etwas, das das Muster enthält, an die Datei angehängt wird. –

+2

Ich kann das gleiche auf mehreren Plattformen bestätigen. Ich hatte nie Probleme mit Tail + Grep genau wie hier beschrieben. Auf welcher Plattform hast du Probleme? –

+1

'Problem ist es nur einmal laufen grep und ist fertig' Nein, das ist nicht richtig. – anubhava

Antwort

6

Wenn dies eine Logdatei ist, kann sie gedreht werden. Es hört dann auf, Daten zu geben.
Dies wird nicht aufhören, wenn die Datei gedreht wird.

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