使用tail -f 命令监视日志输出,如果有异常,执行命令:
方法一:
tail -fn0 logfile | \ while read line ; do echo "$line" | grep "pattern" if [ $? = 0 ] then ... do something ... fi done
方法二:
tail -fn0 logfile | awk '/pattern/ { print | "command" }'
http://stackoverflow.com/questions/4331309/shellscript-to-monitor-a-log-file-if-keyword-triggers-then-execute-a-command
原创文章,转载请注明:转载自Web开发笔记 | Shell Tips: tail 监视日志输出
本文链接地址:https://www.magentonotes.com/shell-tips-tail-execute-command.html
Comments on this entry are closed.