#!/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 本文转自chenzudao51CTO博客,原文链接:http://blog.51cto.com/victor2016/1915372 ,如需转载请自行联系原作者