Last active
September 1, 2020 11:03
-
-
Save antonsem/f7cab00792401815781b8c44fd5c5095 to your computer and use it in GitHub Desktop.
Automatically connect to ExpressVPN on login in Linux (tested on Pop!_OS 20.4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Checks if expressVPN is connected. Connects if not. | |
#Assumes that the expressVPN is installed! | |
#Tested on Pop!_OS 20.4 (LTS) | |
#Let me know if there is a better way to do it, I'm a Linux noob! | |
#Run this script from ~/.profile, and it should work. | |
status=$(expressvpn status) #save the response from the VPN | |
read -ra connected <<< "$status" #seperate individual words | |
#we need only the first word to determine if VPN is connected or not. | |
#However, note that the "Connected" message comes with some kind of | |
#prefix. I couldn't trim it (linux noob) | |
result="${connected[0]}" | |
#we only want to connect if VPN is disconnected. Otherwise we will get | |
#an error. | |
if [ "${result}" == "Not" ]; then | |
gnome-terminal -- bash -c 'expressvpn connect' | |
elif [ "${result:10:9}" != "Connected" ]; then #removed the prefix mentined above. We want to check if the message is the same, or if we need to readjust | |
#the script | |
gnome-terminal -- bash -c 'echo Cannot determine if vpn is connected. Check .profile, condition.txt and statusMessage.txt files at;pwd;echo press any key to close the terminal...;read key' | |
echo "${result}" >> condition.txt | |
echo "Full status message: ${status}" >> statusMessage.txt | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment