|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
欢迎大家来到仓酷云论坛!事情中偶然必要对照文件是不是分歧,经由过程以下剧本能够完成(对照复杂):分享出来,但愿能匡助到有一样需求的伴侣~
#!/bin/bash
#对照办事器上文件是不是一样
#Richardshen2012/07/08
#BLOG:http://lxsym.blog.51cto.com
LC_ALL=en_US.UTF-8
basedir=`dirname$0`
HOST=$basedir/host.txt
PASSWD="abcd"#暗码
FILE=$basedir/file.txt
LOG=$basedir/tmp.log
>$LOG
[!-f/usr/bin/nc]&&yum-yinstallnc
[!-f/usr/bin/expect]&&yum-yinstallexpect
auto_smart_ssh(){
expect-c"settimeout-1;
spawnssh-oStrictHostKeyChecking=no$2${@:3};
expect{
*assword:*{send--$1;
expect{
*denied*{exit2;}
eof
}
}
eof{exit1;}
}
"
#return$?
}
num=0
forfilein`cat$FILE`;do
forhostin`cat$HOST`;do
[[$host=~"^#"]]&&continue
letnum++
if!/usr/bin/nc-w1$host22>/dev/null;then
echo"sshconnectfailed."|tee-a$LOG
continue
else
echo-e"e[32m$host($FILE)MD5comparedfiles...e[0m"
auto_smart_ssh$PASSWDroot@$hostmd5sum$file|grep$file|grep-vStrictHostKeyChecking|tee-a$LOG
fi
done
echo"----------------------------------------------------------"
done
对照的IP地点写进host.txt,必要对照的文件(撑持多个文件)写进file.txt
输入了局为:
192.168.113.108(./file.txt)MD5comparedfiles...
c84509bb3b109506935dba56b667a136/data/server/www/apps/ad/fullcollumn.html
192.168.113.111(./file.txt)MD5comparedfiles...
c84509bb3b109506935dba56b667a136/data/server/www/apps/ad/fullcollumn.html
----------------------------------------------------------
192.168.113.108(./file.txt)MD5comparedfiles...
d2c965f5222ff47432313c76863f428d/data/server/www/apps/ad/sky.html
192.168.113.111(./file.txt)MD5comparedfiles...
d2c965f5222ff47432313c76863f428d/data/server/www/apps/ad/sky.html
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的好朋友们! |
|