首页 > 系统 > Linux > 正文

Shell脚本实现线上服务器之间对比文件是否一致

2019-10-26 18:44:18
字体:
来源:转载
供稿:网友

工作中有时需要对比文件是否一致,通过以下脚本可以实现(比较简单):分享出来,希望能帮助到有同样需求的朋友~

代码如下:
#!/bin/bash
#对比服务器上文件是否一样
# Richard shen 2012/07/08
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 -y install nc
[ ! -f /usr/bin/expect ] && yum -y install expect
auto_smart_ssh () {
    expect -c "set timeout -1;
        spawn ssh -o StrictHostKeyChecking=no $2 ${@:3};
                 expect {
                         *assword:* {send -- $1/r;
                         expect {
                             *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[32m$host ($FILE) MD5 compared files.../e[0m"

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表