How can I launch ProtonVPN, Discord, and Steam in sequence from a shell script?
Asked by
MellowPine47
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?
Answers
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.
Reply to this answer
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.
Reply to this answer
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.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions