I am trying to create an expect script for FortiClient VPN
connection. I base my solution on https://stackoverflow.com/a/19348728/1549135 which works really good.
After successful connection, there is a message saying STATUS::Tunnel running
. Then I have to change my route
settings so that only certain range of IPs would operate over VPN. I try to accomplish it in one expect
script.
I have managed to put down a working solution like this:
#!/usr/bin/expect
spawn /opt/forticlient-sslvpn/64bit/forticlientsslvpn_cli --server $server_ip --vpnuser $user
expect "Password for VPN:" {send $password}
expect "to this server? (Y/N)\r" {send "y\r"}
expect "STATUS::Tunnel running\r"
exec >@stdout 2>@stderr ./enable_internet.sh
interact
enable_internet.sh
#!/bin/bash
sudo route del default ppp0
sudo route add -net 172.20.0.0 netmask 255.255.0.0 dev ppp0
echo "Internet Enabled"
Now I have two problems.
- The
exec
script is launched before"STATUS::Tunnel running\r"
appears on the screen. This might be because there is no{}
but if I add them - it does not work at all. - I want to have everything in one file, so basically I need to move the
bash
commands toexpect
script and call them directly. How to do it?