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\n"} expect "Select page" { send "$ip\n" } expect { "Select account" { send "2\n" expect "Last login" { send "su - admin\n"} } "Select page" { #找一台有权限的机器*.*.*.* send "*.*.*.*\n" expect "Select account" { send "2\n"} expect "Last login" { send "su - admin\n"} expect "]" { send "ssh admin@$ip\n"} expect { "yes/no" { send "yes\n" expect "password" { send "$adminpwd\n" } } "password" { send "$adminpwd\n" } } } } } interact
原文:https://www.cnblogs.com/ZhengQiZHou/p/12670418.html