I'm attempting to script an OpenVPN client connection from within a perl script.
That same perl script, needs to wait (fork and wait?), until the connection is established fully, and then continue the script (talking over the vpn).
After it's done, it will kill the fork, or leave the fork alive, and kill the parent.
I'm trying to figure out the best way to go about this; I'll try to outline the flow as simply as I can...
1. start of perl script...
2. execute some stuff, script determines it needs to talk to a server over the vpn
3. perl dials a vpn connection, either by forking or however method is best
4. child, or other method, signals the main script to continue, as the connection has been established (having it's own IP, and gateway ip, settings and such)
5. main script (parent), continues execution, does some talking over the connection, etc.
6. main script decides by means of conditional if the vpn connection should be left open, and allow the main script to exit; otherwise kill the connection and exit
I've started with this simple bash connect script, and just sleep()'ing for 180 seconds in the main script, after forking off a child which executes the bash script. - Of course, this is not reliable in any way; and I can't really get the connection details back to the main script. (I have to do a few subnet tests, and get the results from a remote server.)
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
echo "Connecting to $remote:$port using $proto..."
--up "/bin/echo Yay up" \
--remote $remote \
--dev tun \
--proto $proto \
--port $port \
--management 127.0.0.1 1194 \
--ca $ca \
--cert $cert \
--key $key \