你还在为登录服务器多次输入密码发愁吗? 你还在为“每一次新开一个窗口 ,就要先敲堡垒机密码、再敲ssh服务器密码”而发愁吗? 下面一段使用expect编写的代码,为你解决上述问题
#!/usr/bin/expect
set timeout 1
spawn ssh -p 22 username@ip_addr
expect "Password:"
send "***\r"
expect "请选择资产分类:"
send "0\r"
expect "请选择目标资产:"
send "2\r"
expect "请选择登录帐号:"
send "1\r"
expect "login:"
send "username\r"
expect "password:"
send "***\r"
interact