第一种方法是通过cmp来进行比对
[root@localhost bo]# ls
.html .html .html .html .html .html .html .html .html cat.sh
[root@localhost 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 ] && echo yes || echo no
[root@localhost bo]# bash cat.sh
yes
[root@localhost bo]# vi .html
[root@localhost bo]# bash cat.
cat.log cat.sh
[root@localhost bo]# bash cat.sh
tmp.log /root/wyb/bo/cat.log differ: byte , line
no
[root@localhost bo]#
第二种方法是通过md5来检验
[root@localhost bo]# ls
.html .html .html .html .html .html .html .html .html cat.log cat.sh md5.sh tmp.log
[root@localhost 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 >&
[ $? -eq ] && success || dosomething [root@localhost bo]# bash md5.sh not change
[root@localhost bo]# echo >> .html
[root@localhost bo]# bash md5.sh
/root/wyb/bo/.html changed !
[root@localhost bo]#
05-17 11:45