The first approach is to use CMP for comparison
[Email protected] bo]#ls1. html2. html3. html4. html5. html6. html7. html8. html9. htmlCat.SH[email protected] bo]#Cat Cat.SH#!/bin/bash[! -f/root/wyb/bo/Cat. log] &&Cat*.html >/root/wyb/bo/Cat. LogCat*.html >Tmp.logCMPtmp.log/root/wyb/bo/Cat. log[$? -eq0] &&EchoYes | |Echono[[email protected] bo]# bashCat.SHYes[[email protected] bo]#VI 2. html [[email protected] bo]# bashCat.Cat. logCat.SH[email protected] bo]# bashCat.SHTmp.log/root/wyb/bo/Cat. Log differ:byte A, line3No[[email protected] bo]#
The second method is to test by MD5
[Email protected] bo]#ls1. html2. html3. html4. html5. html6. html7. html8. html9. htmlCat. logCat.SHMD5.SHTmp.log[[email protected] bo]#CatMD5.SH #!/bin/Bashlang=endosomething () {a=`grep 'FAILED'/tmp/md5.check|awk-F':' '{print $}'` Echo-E"\033[32m$a\033[0m changed!"}find_file () {b=`Find/root/wyb/bo-type f|Xargsmd5sum >/tmp/html.md5 'Echo$b}success () {Echo " not change"}[ ! -F/TMP/HTML.MD5] &&find_file md5sum-c/tmp/html.md5 >/tmp/md5.check2>&1[ $? -eq0] && Success | |dosomething[[email protected] bo]# bash MD5.SHNot Change[[email protected] bo]#Echo 3333>>3. Html[[email protected] bo]# bash MD5.SH/root/wyb/bo/3. HTML Changed![email protected] bo]#
Shell script, how to monitor the contents of the file under the directory is modified.