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\r";exp_continue
}
"*assword"
{
send "${passwd}\r"
}
}
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
贵有恒,何必三更起五更睡;最无益,只怕一日暴十寒