方法一:md5sum [root@shnne scripts]# cat diffpro.sh #!/bin/sh path=/server/scripts/cuangai [ ! -d $path ] && mkdir -p $path [ ! -f $path/diff.log ] && touch $path/diff.log || cat /dev/null >$path/diff.log webpath=/application/nginx/html filedb=$path/file_md5.db find $webpath -type f|xargs md5sum >$filedb linedb=$path/line.db find $webpath -type f >$linedb while true do newlinedb=$path/newline.db find $webpath -type f >$newlinedb flag1=`md5sum -c "$filedb" 2>/dev/null|grep "FAILED"|wc -l` flag2=`diff "$linedb" "$newlinedb"|wc -l` if [ $flag1 -ne 0 ] || [ $flag2 -ne 0 ] then echo "$(date +%F" "%T)" "`diff "$linedb" "$newlinedb"`" >>$path/diff.log echo "$(date +%F" "%T)" "`md5sum -c "$filedb" 2>/dev/null|grep "FAILED"`" >>$path/diff.log cat $path/diff.log echo "********************************************" else echo "the file is not change." fi sleep 5 done
方法二:用inotify检测