如何使用linux expect脚本输入应答密码提示

wbl*_*enc 5 linux command-line expect

我在编写脚本时遇到一些麻烦,该脚本将启动我的forticlient vpn命令行客户端并在提示时发送我的密码.这是我的代码:

#!/usr/bin/expect -f
set loadme "./forticlientsslvpncli --server myvpnserver --vpnuser theuser
eval spawn $loadme
expect "Password for VPN: "
send "password\r"
Run Code Online (Sandbox Code Playgroud)

但是,它仍然提示输入vpn密码.我确信这是一个简单的东西,我对linux脚本很新,但任何帮助将不胜感激!

谢谢!

小智 13

#!/usr/bin/expect -f
set timeout -1
cd /usr/local/forticlientsslvpn
spawn ./forticlientsslvpn_cli --server myhost:10443 --vpnuser myuser
expect "Password for VPN:" {send -- "mypassword\r"}
expect "to this server? (Y/N)\r" {send -- "y\r"}

expect eof
Run Code Online (Sandbox Code Playgroud)


wbl*_*enc 4

从格伦·杰克曼那里得到的评论中,我发现密码提示不匹配。我将第一行更改为#!/var/bin/expect -d 提供必要的调试输出以找出问题并修复它。

谢谢格伦!