Chinaunix首页 | 论坛 | 博客
  • 博客访问: 538813
  • 博文数量: 102
  • 博客积分: 950
  • 博客等级: 准尉
  • 技术积分: 1094
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-28 16:07
文章分类

全部博文(102)

文章存档

2020年(2)

2016年(5)

2015年(15)

2014年(25)

2013年(18)

2012年(19)

2011年(18)

我的朋友

分类: LINUX

2014-09-02 09:54:45

#!/bin/env sh

#PURPOSE:
# 1. check flag file's time status, if status stop so action
# 2. action is netcard down, default is eth0 , may be yourself modify name
#
#NOTE:
# 1. change script exec priv: chmod 755 checkFileAction.sh and boot command: "nohup Path/checkFileAction.sh &", let it background exec, must user root exec 
# 2. script exit when action command end. so next run must manual boot script
# 3. param checksecond must greater than 2 second
# 4. param checkFile may by modify


checkSecond=10
checkFile='/root/status.log'


netCardName='eth0'
actionCMD="/sbin/ifconfig $netCardName down"


dateCMD='/bin/date'
LOG='/tmp/checkFileAction.log'
 
echo -e "\n[`$dateCMD +%F' '%T`] $0 script begin runing..." >>$LOG
if [ ! -e "$checkFile" ]; then
echo "[`$dateCMD +%F' '%T`] $checkFile file no exists, abnormal exit!" >>$LOG
exit 1
fi
NowTime=`$dateCMD +%s`
while(true)
do
sleep $checkSecond


getFilerev=`export=C ls -l --full-time $checkFile | awk '{print $6,$7}'`
FileTime=`$dateCMD -d "$getFilerev" +%s`
distance=$(($FileTime - $NowTime))


if [ $distance -lt 0 ]; then
echo "[`$dateCMD +%F' '%T`] $checkFile status no update in $checkSecond second, Prog abnormal!" >>$LOG
echo "[`$dateCMD +%F' '%T`] exec command: $actionCMD" >>$LOG
$actionCMD 2>&1 >>$LOG
exit 1
else
NowTime=`$dateCMD +%s`
echo "[`$dateCMD +%F' '%T`] $checkFile status update normal in $checkSecond second." >>$LOG
fi
done

阅读(927) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~