ssh的例子:
user01=admin
IP01=192.168.44.113
expect -c "
set timeout 60
spawn ssh $user01@$IP01
expect {
\"yes/no\" {
sleep 1
send \"yes\\n\"
exp_continue
}
\"ssword:\" {
sleep 1
send \"admin123\\n\"
}
timeout { exit 1}
}
interact
"
telnet的例子:
user01=admin
IP01=10.200.200.1
expect -c "
set timeout 60
spawn telnet $IP01
expect {
\"Username\" {
sleep 1
send \"admin\n\"
exp_continue
}
\"ssword:\" {
sleep 1
send \"wp1@gw.com\\n\"
}
timeout { exit 1}
}
interact
"

本文提供了使用Expect脚本实现SSH及Telnet自动化登录的示例代码。通过设置超时时间、发送用户名和密码等操作,可以实现对远程主机的安全登录。适用于批量管理和维护远程服务器场景。
414

被折叠的 条评论
为什么被折叠?



