Estou usando este código (você precisa instalar o pacote expect
primeiro):
Eu instalei forticlientsslvpn_cli
em /opt/forticlientsslvpn
.
Substitua IP_FORTIGATE
, PORT_FORTIGATE
, VPN_USERNAME
e VPN_PASSWORD
com seus valores.
#!/usr/bin/expect -f
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
send -- "cd /opt/forticlientsslvpn/\r"
send -- "./forticlientsslvpn_cli --server IP_FORTIGATE:PORT_FORTIGATE --vpnuser VPN_USERNAME"
expect -exact "./forticlientsslvpn_cli --server IP_FORTIGATE:PORT_FORTIGATE --vpnuser VPN_USERNAME"
send -- "\r"
expect -exact "\r
Password for VPN:"
send -- "VPN_PASSWORD\r"
expect -exact "\r
STATUS::Setting up the tunnel\r
STATUS::Connecting...\r"
send -- "Y\r"
expect eof