第一种方法是通过cmp来进行比对[[email protected] bo]# ls 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html cat.sh [[email protected] bo]# cat cat.sh #!/bin/bash [ ! -f /root/wyb/bo/cat.log ] && cat *.html > /root/wyb/bo/cat.log cat *.html >tmp.log cmp tmp.log /root/wyb/bo/cat.log [ $? -eq 0 ] && echo yes || echo no [[email protected] bo]# bash cat.sh yes [[email protected] bo]# vi 2.html [[email protected] bo]# bash cat. cat.log cat.sh [[email protected] bo]# bash cat.sh tmp.log /root/wyb/bo/cat.log differ: byte 12, line 3 no [[email protected] bo]#
第二种方法是通过md5来检验[[email protected] bo]# ls 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html cat.log cat.sh md5.sh tmp.log [[email protected] bo]# cat md5.sh #!/bin/bash LANG=en dosomething() { a=`grep ‘FAILED‘ /tmp/md5.check|awk -F‘:‘ ‘{print $1}‘` echo -e "\033[32m$a\033[0m changed !" } find_file(){ b=`find /root/wyb/bo -type f|xargs md5sum > /tmp/html.md5` echo $b } success() { echo "not change" } [ ! -f /tmp/html.md5 ] && find_file md5sum -c /tmp/html.md5 > /tmp/md5.check 2>&1 [ $? -eq 0 ] && success || dosomething [[email protected] bo]# bash md5.sh not change [[email protected] bo]# echo 3333 >> 3.html [[email protected] bo]# bash md5.sh /root/wyb/bo/3.html changed ! [[email protected] bo]#
时间: 2024-08-07 23:09:26