脚本首先检查日志文件是否存在,不存在则创建文件。 然后检索日志文件最后20行,匹配到关键字则报警。
logfile=/opt/dmdbms/log/dm_dmwatcher_V3X8_$(date +%Y%m).log
if [ ! -f "$logfile" ];then
touch $logfile
chmod -R 777 $logfile
fi
format_date=$(date +%s -r $logfile)
now_date=$(date +%s)
result=$(tail -n 20 $logfile)
if [ $(($now_date-$format_date)) -gt 600 ];then
echo 'Normal'
else
if [[ ${result} =~ '实例状态(MOUNT)' ]];then
echo 'MountError'
elif [[ ${result} =~ '没有收到远程守护进程' ]];then
echo 'NetworkError'
elif [[ ${result} =~ '原状态是' ]];then
echo 'ChangeError'
else
echo 'Normal'
fi
fi