Shell script, how to monitor the contents of the file under the directory is modified.

Source: Internet
Author: User
Tags md5

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.