使用expect批量自动登录服务器并执行命令
- 作者: 吃饱了闲的
- 来源: 51数据库
- 2022-09-21
#!/bin/bash
cat iplist|while read line #iplist文件中存放了IP地址和密码,每行格式为“IP地址 密码”
do
a=($line) #a为数组
/usr/bin/expect<<EOF
spawn ssh root@${a[0]}
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" { send "${a[1]}\r" }
}
expect "#"
send "hostname\r"
send "exit\r"
expect eof
EOF
done
推荐阅读
