Shellscript监视日志文件(如果关键字触发然后执行命令)? [英] Shellscript to monitor a log file if keyword triggers then execute a command?
本文介绍了Shellscript监视日志文件(如果关键字触发然后执行命令)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种便宜的方法来监视类似tail -f log.txt
的日志文件,然后如果出现类似[error]
的东西,执行命令?
Is there a cheap way to monitor a log file like tail -f log.txt
, then if something like [error]
appears, execute a command?
谢谢.
推荐答案
tail -fn0 logfile | \
while read line ; do
echo "$line" | grep "pattern"
if [ $? = 0 ]
then
... do something ...
fi
done
这篇关于Shellscript监视日志文件(如果关键字触发然后执行命令)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文