I want to use a bash script to start an openvpn connection and once I got the tunnel established start an SSH terminal connection to a server and once I close the SSH connection also close the openvpn connection.
For the start, I tried implementing the solution proposed at https://stackoverflow.com/questions/21001220/bash-sequence-wait-for-output-then-start-next-program as a shell script
#!/bin/bashexec 3< <(sudo openvpn --config /etc/openvpn/server.ovpn)sed '/Initialization Sequence Completed$/q'<&3 ; cat <&3 &ssh server
I run this script as sh ssh-vpn.sh in the fish shell.
As a script, this gives me a syntax error line 2: syntax error near unexpected token '<'
. outside of the script, I do not get this error.
Also, not using these command as a script, I occasionally seemed to have gotten error messages because the file descriptor 3 was already existing.
How to avoid the syntax error in the script?
How to extend the script so that it automatically closes the openvpn connection afterwards?
How to ensure the file descriptor gets closed at end of script?
I apologise if this is too much for one question - I guess this is one of my first scripting questions for a long time and I still have to learn much here.