简体   繁体   中英

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. 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:

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

Try running with expect -d to see why your pattern is not matching when you lose connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM