Write to file after pipeline output from tail -f to grep

I am looking for a write to a file after piping the tail from -f to grep. Say write to the file "temp" for all lines with "Playing:" inside in error_log "FreeSwitch.log".

 tail -f "/var/lof/freeswitch/freeswitch.log" | grep "Playing:" > temp

but does not work! This is centos 5.5

+3
source share
4 answers

Perhaps you have a buffering problem? See BashFAQ: What is Buffering ?

You can, for example, try:

tail -f /var/lof/freeswitch/freeswitch.log | grep --line-buffered "Playing:" > temp
+10
source
-f, --follow[={name|descriptor}]
              output appended data as the file grows;

It scans the file as it grows. And this is an interval process. You can only interrupt it.

Use parameter:

-c, --bytes=K
              output the last K bytes; alternatively, use -c +K to output bytes starting with the Kth of each file  

or

-n, --lines=K
              output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth

EDIT: as bmk said:

grep --line-buffered  

think it helps you

+2
source

>?

tail -f /var/lof/freeswitch/freeswitch.log | grep "Playing:" > temp
0

.

mysql "":

tail -f /var/log/httpd/error_log | \
grep -E --line-buffered "error" | \
while read line; do \
#echo -e "MY LINE: ${line}"; done
echo "INSERT INTO logs (logid,date,log) VALUES (NULL, NOW(), '${line}');" | mysql -uUSERDB -pPASSDB DBNAME; done
0

All Articles