Automatic ExpressVPN Shutdown Script?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
kanichiro
Level 3
Level 3
Posts: 179
Joined: Thu Nov 07, 2013 11:23 am
Location: Frostbite Falls, MN

Automatic ExpressVPN Shutdown Script?

Post by kanichiro »

I have a script (gleaned from multiple posts in these forums) to start ExpressVPN automatically at startup.

Code: Select all

#!/bin/sh
expressvpn connect Germany
@reboot ( sleep 15 ; sh /home/mederia/expressvpnstart.sh 
However, is it possible to create a script to automatically shutdown ExpressVPN when I click the Shutdown button in Linux?

I would think a proper shutdown of ExpressVPN would be preferable to a hard disconnect by just shutting down my laptop.

I am NOT a coder so please be kind :|

Thanks ahead of time!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Automatic ExpressVPN Shutdown Script?

Post by rene »

The @reboot seems to imply that last line not being part of the script but being a crontab line? (even though the opening brace would seem to be invalid syntax)

That is, where is this script of yours? If expressvpn needs e.g. X running a systemd user service may be useful here; if not, it's if it's late enough going to be the by far easiest to just add

Code: Select all

expressvpn connect Germany
to a file /etc/rc.local, made executable with sudo chmod +x /etc/rc.local.

But, needs more context...
kanichiro
Level 3
Level 3
Posts: 179
Joined: Thu Nov 07, 2013 11:23 am
Location: Frostbite Falls, MN

Re: Automatic ExpressVPN Shutdown Script?

Post by kanichiro »

I put that script together this week and it works, but I found that I do not need the last line of that script to get ExpressVPN to run so I removed it.

Code: Select all

@reboot ( sleep 15 ; sh /home/mederia/expressvpnstart.sh 
However, that is NOT the reason I posted the OP, the reason is that ExpressVPN starts and stops through the Terminal. I now have a script to start ExpressVPN at login but I would like to have a script that automatically shuts down ExpressVPN when I shutdown my laptop.

As it stand now before I shutdown my lappy, I need to enter ExpressVPN Disconnect into the Terminal to shutdown the VPN service before I press the Shutdown button for Linux Mint.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Automatic ExpressVPN Shutdown Script?

Post by rene »

So please answer the question. It is still unclear when and how you are launching your script and that's information needed to be able to advise on when and how to "delaunch" it.
kanichiro
Level 3
Level 3
Posts: 179
Joined: Thu Nov 07, 2013 11:23 am
Location: Frostbite Falls, MN

Re: Automatic ExpressVPN Shutdown Script?

Post by kanichiro »

Sorry Rene, I misunderstood!

The ExpressVPNStart.sh script is in my Home directory.

I created the Startup in System Settings/Startup Applications
Note: I changed the startup time to a 25-second delay in order for the other startup apps to begin running. However, I am not sure if that is necessary.

ExpressVPN Startup.1.png


ExpressVPN Startup.2.png
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Automatic ExpressVPN Shutdown Script?

Post by rene »

OK, yes, there is no (convenient) counterpart to the desktop startup applications. Can be worked around with f.e. a systemd user service but in your case the much better answer is integrating ExpressVPN with NetworkManager as per

https://www.expressvpn.com/support/vpn- ... h-openvpn/

That is, disable/remove your Startup Application, configure the VPN through NetworkManager as per the above guide, test that you can connect it manually (leftclick networking icon in systray and select it) and if all well, go into your main connection profile (leftclick same networking icon -> Network connections -> (e.g.) Ethernet/Wired Connection -> Gear Icon ->General -> Automatically connect to VPN when using this connection.

I remember an issue there during Mint 18 times but I just checked and all's working well on 19.1. You then have a "fully native" and fully integrated VPN setup, without any need for provider-specific tools such as that "expressvpn" one.
kanichiro
Level 3
Level 3
Posts: 179
Joined: Thu Nov 07, 2013 11:23 am
Location: Frostbite Falls, MN

Re: Automatic ExpressVPN Shutdown Script?

Post by kanichiro »

Thank you for the information, Rene.

However, I first signed up for a VPN with CyberGhost last November. CyberGhost uses the same, or nearly the same setup as in the link you posted from ExpressVPN. While I was able to connect to CyberGhost, I was never able to get the DNS leak to stop. I worked with CyberGhost support on that issue for about 5-weeks before they admitted defeat and said they would give me a refund.

Note: With CyberGhost using that technique as described, I still had to manually click the VPN connection in available Networks to connect to CyberGhost. And before shutdown I needed to go back and turn off the CyberGhostVPN connection.

Soon after I received my refund from CyberGhost, I signed up with ExpressVPN and using their login with the Terminal feature I was able to immediately connect to ExpressVPN, with no DNS leaks at all. I was having to manually connect to ExpressVPN through the Terminal after startup every day when I found some code to automatically connect to ExpressVPN as in my original post. That is why I just wanted a script to automatically disconnect ExpressVPN from the Terminal at shutdown. I will just continue to do this manually.

Having spent 5-weeks or so with CyberGhost messing with the setup described in the link you provided, I think I'll stick with what I am using now. The ExpressVPN setup might work, but it might put me in the same position I was with CyberGhost. I might try it at a later date, but not now. I spent too much time and effort on that already.


Thank you anyway! Your help was very much appreciated!
Locked

Return to “Scripts & Bash”