#!/bin/bash
#The owner is Echo.Atlas
mtime=`stat -c %Y /logs/blackhole/main.log`
systime=`date +%s`
if [ $[ $systime - $mtime ] -gt 21600 ]
then
echo "This file has been updated for more than 6 hours"
else
echo "The file status is true"
fi
应用情景
main.log 是程序输出的日志文件,若程序出现假死(进程服务都在,却不工作),main.log文件中无更新,以最后一条内容的时间(即mtime)与系统当前时间比对。若超过21600秒则输出自定义内容。
ps:1、mtime和系统时间都要做时间戳转换
2、可结合监控程序进行报警处理
本文出自 “Dr小白” 博客,请务必保留此出处http://metis.blog.51cto.com/1203503/1953376
原文地址:http://metis.blog.51cto.com/1203503/1953376