#!/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
阅读(940) | 评论(0) | 转发(0) |