Created
May 12, 2015 08:09
-
-
Save orangle/727f212048aabb9b0f60 to your computer and use it in GitHub Desktop.
监控配置文件变化,并且执行对应的操作。 monitoring file changed, and do some action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#author: orangleliu@gmail.com | |
#use this shell script with cron | |
file=/home/ftp/rulebase/rules.list | |
md5checkfile=/tmp/rulebase.md5 | |
if [ ! -f $file ] | |
then | |
echo "$file not exist .." | |
exit 1 | |
fi | |
filemd5=`md5sum $file |cut -d " " -f1` | |
echo "filemd5 $filemd5" | |
if [ -z $filemd5 ] | |
then | |
echo "the $file is empty" | |
exit 1 | |
fi | |
if [ -f $md5checkfile ] | |
then | |
savedmd5=`cat $md5checkfile` | |
echo "saved md5 $savemd5" | |
if [ "$savedmd5" = "$filemd5" ] | |
then | |
echo "not changed" | |
else | |
echo "File has ben changed" | |
#restart some service | |
/bin/sh /home/ftp/rulebase/udpserver.sh restart | |
fi | |
fi | |
echo $filemd5 > $md5checkfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment