实时监控日志 我们常用的方法是
tail -f logfile
但是 ,将其用到 脚本中 就会卡死了 ,跟同事学习讨论了一天 (主要是学习)决定用sed -n 来替代
sed -n '/datea/,/dateb/p'
分别定义 两个时间变量 中间间隔 3分钟
下附脚本
#!/bin/bash
#
#filename=sed_exception.sh
date_ago=`date +'%F %H:%M' -d '3 minutes ago'`
date=`date +'%F %H:%M'`
dir=/usr/local/red5/log/red5.log
sed -n "/${date_ago}/,/${date}/p" $dir | /bin/grep "Exception" > /dev/null
if [[ -z "$?" ]];then
echo 1
else
echo 0
fi