I want to create a Bash script that starts ProtonVPN first, then launches Discord and Steam so they use the VPN's split-tunnel configuration. The problem is that applications such as ProtonVPN may keep running in the foreground or may not return a useful status when they stay open. What is the best way to start them in the background and make sure the VPN is connected before launching the other applications?
3 Answers
Use `&` to start a command as a background job. For example, once the VPN has been started, you can launch the other applications without blocking the script:
```bash
#!/bin/bash
/path/to/discord &
/path/to/steam &
```
You can also put the VPN command in the background, but you should verify that the connection is actually established before starting Discord and Steam.
Instead of relying on a fixed delay, check whether the VPN tunnel exists. First find the interface name with `ip address`—it might be `proton0` on your system. Then you can test it with something like:
```bash
if ip address show proton0 | grep -q 'proton0:'; then
discord &
steam &
else
echo "Please connect to the VPN first"
fi
```
The `-q` option keeps `grep` from printing the matching line, and its exit status can be used directly by the `if` statement. Replace `proton0` with the actual tunnel interface name if necessary.
A simple approach is to start the VPN, wait briefly for it to connect, and then launch the applications:
```bash
#!/bin/bash
start-protonvpn &
sleep 20
discord &
steam &
```
However, a fixed `sleep` duration is only a rough solution because connection times vary. A loop that checks for the VPN interface—or a ProtonVPN command that reports connection status—is more reliable. Plain `wait` is generally not appropriate if the VPN process is intended to keep running, because the script would wait for that long-running process to exit.

Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures