[英]write to a file after piping output from tail -f through to grep
I'm looking to write to a file after piping output from tail -f through to grep. 我想在从tail -f到grep的管道输出之后写一个文件。 Say,write to a file "temp" for all lines with "Playing:" within in error_log "FreeSwitch.log". 比如说,在error_log“FreeSwitch.log”中写入“播放:”所有行的文件“temp”。
tail -f "/var/lof/freeswitch/freeswitch.log" | grep "Playing:" > temp
but not working ! 但不工作! It is a centos 5.5 这是5.5美元
Maybe you have an issue with buffering? 也许你有缓冲问题? See BashFAQ: What is buffering ? 见BashFAQ:什么是缓冲 ?
You could eg try: 你可以尝试:
tail -f /var/lof/freeswitch/freeswitch.log | grep --line-buffered "Playing:" > temp
-f, --follow[={name|descriptor}]
output appended data as the file grows;
It scans the file as it grows. 它会随着文件的增长扫描文件。 And it is a process with an interval. 这是一个间隔的过程。 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: 编辑:正如bmk所说:
grep --line-buffered
think it will help you 认为它会对你有所帮助
你把文件名放在>
后面了吗?
tail -f /var/lof/freeswitch/freeswitch.log | grep "Playing:" > temp
thanks for your help. 谢谢你的帮助。
here is my code to insert into mysql with the word "error": 这是我的代码插入到mysql中的单词“error”:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.