[英]How to use a linux expect script to reconnect to forticlientvpn
I have this code that connects my network to an external vpn, but sometimes this connection is lost. 我有将我的网络连接到外部VPN的代码,但是有时此连接丢失。 I need my code to detect the error and try to connect again.
我需要我的代码来检测错误,然后尝试重新连接。
set force_conservative 0
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout -1
spawn $env(SHELL)
match_max 100000
proc tryconnection {} {
send -- "./forticlientsslvpn_cli --server SERVER:PORT --vpnuser USER"
expect -exact "./forticlientsslvpn_cli --server SERVER:PORT --vpnuser USER"
send -- "\r"
expect -exact "\r\nPassword for VPN:"
send -- "PASSWORD\r"
expect -exact "\r\nSTATUS::Setting up the tunnel\r\nSTATUS::Connecting...\r"
send -- "Y\r"
expect -exact "\r\nSSLVPN down unexpectedly with error:6\r" {
puts "Send Ctrl+C"
send \003
tryconnection
}
expect eof
}
tryconnection
I would remove the -exact
option: 我将删除
-exact
选项:
expect "*SSLVPN down unexpectedly with error:6*" { ...
Try running with expect -d
to see why your pattern is not matching when you lose connection. 尝试与
expect -d
一起运行,以查看丢失连接后为什么模式不匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.