如何使用linux expect脚本重新连接到forticlientvpn

时间:2015-09-30 00:59:22

标签: linux bash shell expect vpn

我有这个代码将我的网络连接到外部vpn,但有时这个连接会丢失。我需要我的代码来检测错误并尝试再次连接。

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

1 个答案:

答案 0 :(得分:0)

我会删除-exact选项:

expect "*SSLVPN down unexpectedly with error:6*" { ...

尝试使用expect -d运行,以查看丢失连接时模式不匹配的原因。