自动登录脚本

 

#!/usr/bin/expect -f

set timeout 10

set root2name "root"
set root2pass "abc"

set ip_addrs [list 192.168.180.120]

foreach IP $ip_addrs {
spawn ssh -p 22989   -o StrictHostKeyChecking=no $root2name@$IP
expect {
"(yes/no)?" {send "yes\r";       exp_send continue}
sleep 2
"password:" {send "$root2pass\r"; exp_send continue}
}
expect "]"

send "cd ~\r"
expect "#"

interact;
 

本文出自 “linux系统与网络” 博客,谢绝转载!

你可能感兴趣的:(脚本,自动登录)