I have a script, that starts my server. I want to start openvpn client before it. Here my current working solution:


openvpn --client --config $OVPN_CONFIG &

sleep 10

npm start

I want to avoid sleep and check openvpn sucessfull running by output line:

Tue May 14 16:35:50 2019 Initialization Sequence Completed

How to do that? Note, that this script used as docker container entrypoint.

  • Did my solution work for you? If not, I would be happy if you could point out the problems you had with it. – Socowi Jun 5 at 11:14

The following bash one-liner runs openvpn, waits for the output Init... Completed, immediately starts npm, and continues to run openvpn in the background.

#! /bin/bash
grep -qF 'Initialization Sequence Completed' <(openvpn ...) && npm start

In case openvpn never prints Init... Completed the whole command will terminate after openvpn terminates without starting npm.

Since I have neither openvpn nor npm installed I use the following functions to emulate their behavior.

openvpn() {
  echo "something something"
  sleep 1
  echo "$(date) Initialization Sequence Completed"
  sleep 1
  echo "openvpn still running" >&2 # prints to stderr so that we see it 
npm() {
  echo "started npm"

With these the output of the one-liner from above is

started npm
openvpn still running

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.