bashubuntuubuntu-16.04notify-send

how to run 2 lines on in bash side by side


I am new to Bash and I am trying to have this script notify me when I am connected and disconnected to my VPN.

The problem I have is when I run my "openvpn" it will stop listening to the rest of the lines that follow so I had to put my "connected" notification line before I even log in. Is there a more ideal way that I can write this so that my "connected" line will only run when the open vpn line has connected?

If it helps this is for Ubuntu.

#!/bin/bash

set -e

function discon {
  notify-send -i /usr/share/icons/Adwaita/32x32/devices/network-vpn.png "Home Network" "Disconnected"
}

notify-send -i /usr/share/icons/Adwaita/32x32/devices/network-vpn.png "Home Network" "Connected"

openvpn --config /home/matthew/Documents/vpn/MatthewLaptop.ovpn

trap discon EXIT

Solution

  • You can append & to detach the process from the terminal. Otherwise bash will only continue the script when openvpn exits.

    openvpn --config /home/matthew/Documents/vpn/MatthewLaptop.ovpn &