linux expect自动登陆远程服务器 批量管理服务器

#!/usr/bin/expect
 
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 3
 
spawn ssh root@${ipaddress}
 
expect {
        "yes/no" 
                {
                        send "yes
";exp_continue
                }
 
        "*assword"
                {
                        send "${passwd}
"
                }
}
expect "*from*"
send "mkdir -p /home/hahahahha"   #在远程服务器创建/home/hahahahha 的文件夹
expect "]#"
expect eof
 
 
#
for i in `awk '{print $1}' passwd.txt`
do
        j=`awk -v I="$i" '{if(I=$i)print $2}' passwd.txt`
        expect /root/2_ssh.exp $i $j
done
原文地址:https://www.cnblogs.com/rayong/p/7269472.html