1

How to run write a bash script to do a task after an openvpn connection as

#!/bin/bash
openvpn --config file.ovpn (step 1)
RUN THE TASK AFTER THE CONNECTION (step 2)
THEN DISCONNECT FROM THE OPENVPN (step 3)

My problem is how to move from the step 1 to step 2. I tried up and daemon options in openvpn to trigger step 2 in background, but in this case, we do not know when step 2 is finished to trigger step 3.

The problem is how to use openvpn as a regular command in a bash script to go to the next line when the connection is established.

  • killall openvpn – GAD3R Apr 22 '17 at 13:20
  • @GAD3R I edited the question to explain the problem. – Googlebot Apr 22 '17 at 15:59
2
#!/bin/bash
sudo systemctl start openvpn@vpnname # (step 1)
# RUN THE TASK AFTER THE CONNECTION (step 2)
sudo systemctl stop openvpn@vpnname # (step 3)

vpnname must be replaced with the name of a vpn connection configured at /etc/openvpn/. For example, /etc/openvpn/vpnname.conf

  • This is useful. Also for keeping exactly one --daemonized openvpn client prozess running/stopped in the background, for each available .conf / connection. Furthermore, systemctl will trigger sudo if required. – user18099 Sep 21 '18 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.