expect脚本的用法
然后通过spawn执行一个想要的操作,在通过expect命令,当检测到紧跟着的参数字样的输出时,通过send命令交互式的发送想要执行的操作。最后通过interact结束expect脚本对屏幕输出的监控
#!/usr/bin/expect -f set ip [lindex $argv 0] set cmd [lindex $argv 1] set adminpwd ****** set rootpwd ****** spawn sshpass -p 密码 ssh 跳板机ip if { $ip != "" } { expect "Select group" { send "0 "} expect "Select page" { send "$ip " } expect { "Select account" { send "2 " expect "Last login" { send "su - admin "} } "Select page" { #找一台有权限的机器*.*.*.* send "*.*.*.* " expect "Select account" { send "2 "} expect "Last login" { send "su - admin "} expect "]" { send "ssh admin@$ip "} expect { "yes/no" { send "yes " expect "password" { send "$adminpwd " } } "password" { send "$adminpwd " } } } } } interact