shell免交互批量为服务器做些事情

@努力的小王  March 30, 2018

passwd.txt 定义主机ip和密码

#!/bin/env bash
##this is don't interactive script
##author xw 2018.3.30
while read line
do 
      
       {
       ip=`echo $line |awk '{print $1}'`
       password=`echo $line |awk '{print $2}'`
     
       /usr/bin/expect <<-EOF
       set timeout 5
       spawn rsync -va /etc root@$ip:/tmp
       spawn rsync -va /    root@$ip:/tmp ##可以让他连续干活
       expect {
               "yes/no" { send "yes\r";exp_continue }
               "password:" { send "$password\r"; }
       }
       expect eof
EOF


       }&
done < passwd.txt
wait
echo "please Wait a moment"

添加新评论