Compare whether the files on the shell online server are consistent

Source: Internet
Author: User
At work, you sometimes need to compare whether the files are consistent. You can use the following script (relatively simple): share it and hope to help friends who have the same requirements ~ #! /Bin/bash # compare whether files on the server are the same # Richard shen2012/07/08 # BLOG: http://lxsym.blog.51cto.comLC _ ALL = 'en _ US.UTF-8 'basedir = 'dirname $0'

At work, you sometimes need to compare whether the files are consistent. You can use the following script (relatively simple): share it and hope to help friends who have the same requirements ~
#! /Bin/bash
# Compare to whether files on the server are the same
# Richard shen 2012/07/08
# BLOG: http://lxsym.blog.51cto.com
LC_ALL = 'en _ US.UTF-8'
Basedir = 'dirname $0'
HOST = $ basedir/host.txt
PASSWD = "abcd" # Password
FILE = $ basedir/file.txt
LOG = $ basedir/tmp. log
> $ LOG
[! -F/usr/bin/nc] & yum-y install nc
[! -F/usr/bin/keep CT] & yum-y install keep CT
Auto_smart_ssh (){
CT-c "set timeout-1;
Spawn ssh-o StrictHostKeyChecking = no $2 $ {@: 3 };
CT {
* Assword: * {send -- $1 \ r;
CT {
* Denied * {exit 2 ;}
Eof
}
}
Eof {exit 1 ;}
}
"
# Return $?
}
Num = 0
For file in 'cat $ file'; do
For host in 'cat $ host'; do
[[$ Host = ~ "^ #"] & Continue
Let 'num ++'
If! /Usr/bin/nc-w 1 $ host 22>/dev/null; then
Echo "ssh connect failed." | tee-a $ LOG
Continue
Else
Echo-e "\ e [32 m $ host ($ FILE) MD5 compared files... \ e [0 m"
Auto_smart_ssh $ PASSWD root @ $ host md5sum $ file | grep-v StrictHostKeyChecking | tee-a $ LOG
Fi
Done
Echo "----------------------------------------------------------"
Done

Compare the IP address to the host.txt file, and compare the file (support multiple file types to the file.txt file)
Output result:

192.168.113.108 (./file.txt) MD5 compared files...
C84509bb3b450506935dba56b667a136/data/server/www/apps/ad/fullcollumn.html
192.168.113.111 (./file.txt) MD5 compared files...
C84509bb3b450506935dba56b667a136/data/server/www/apps/ad/fullcollumn.html
----------------------------------------------------------
192.168.113.108 (./file.txt) MD5 compared files...
D2c965f5222ff47432313c76863f428d/data/server/www/apps/ad/sky.html
192.168.113.111 (./file.txt) MD5 compared files...
D2c965f5222ff47432313c76863f428d/data/server/www/apps/ad/sky.html

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.