The Computer Oracle

How to execute multiple scripts when openvpn establishes?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Music Box Puzzles

--

Chapters
00:00 How To Execute Multiple Scripts When Openvpn Establishes?
00:46 Accepted Answer Score 7
01:10 Answer 2 Score 11
01:44 Answer 3 Score 3
01:49 Thank you

--

Full question
https://superuser.com/questions/505012/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#vpn #openvpn

#avk47



ANSWER 1

Score 11


Just for reference. If you have a few scripts and timing isn't crucial you can also use another parameter for executing scripts.

Script Order of Execution

--up
Executed after TCP/UDP socket bind and TUN/TAP open.
--tls-verify
Executed when we have a still untrusted remote peer.
--ipchange
Executed after connection authentication, or remote IP address change.
--client-connect
Executed in --mode server mode immediately after client authentication.
--route-up
Executed after connection authentication, either immediately after, or some number of seconds after as defined by the --route-delay option.
--client-disconnect
Executed in --mode server mode on client instance shutdown.
--down
Executed after TCP/UDP and TUN/TAP close.
--learn-address
Executed in --mode server mode whenever an IPv4 address/route or MAC address is added to OpenVPN's internal routing table.
--auth-user-pass-verify
Executed in --mode server mode on new client connections, when the client is still untrusted.

https://openvpn.net/index.php/open-source/documentation/manuals/65-openvpn-20x-manpage.html




ACCEPTED ANSWER

Score 7


A quick hack would be to call the 2nd script from the end of the last one:

Just add the following to the end of the '/etc/openvpn/update-resolv-conf' script:

/etc/openvpn/vpn-up.sh

I'm sure people here will provide a more elegant way to do this.




ANSWER 3

Score 3


up '/bin/bash -c "/etc/openvpn/update-resolv-conf; /etc/openvpn/vpn-up.sh"'