How to make my PC execute a script after it established a connection to the internet?
My particular case is to connect to a ProtonVPN. ProtonVPN ships a command line tool (protonvpn-cli from the AUR) to do this.
At the moment I just start a little script a few seconds after login to KDE. It works fine most of the time, but it is not very elegant nor practical especially on a laptop.
I am sure it is explained somewhere in the wiki, but I have not found it so far and I don't know how to search for it.
Even a slight hint or a link to the arch wiki would most likely help me out.
Edited 21 Jul 2021. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 3 · 81% up
- Kind
- Text
- ID
- ool1o6
12 comments
Just use a systemd service. Something like
Note that you'll need to create another unit if you want your first unit to be automatically restarted after resuming from suspend/hibernate, see my comment here
Well ofc one can do this with systemd. I should have thought about it! Thx for this suggestion!
Also look at this to go down the Network Manager route rather than systemd.
https://wiki.archlinux.org/title/NetworkManager#Network_services_with_NetworkManager_dispatcher
One side note. There is a way to connect to Proton via openVPN. If you do that, there is a checkbox in Network Manager gui to auto connect to a VPN for certain networks.
Good hint!
I was thinking about using openVPN. But Proton advices to use their tools. And I thought it is easier to setup and to maintain. You don't have to update any openVPN config files when proton changes anything.
Are you using protonVPN? Do you connect to it via openVPN?
Yes, I think this is exactly what I was looking for! This seems as simple as it should be. Thx!
https://wiki.archlinux.org/title/Autostarting
Yeah I looked at that wiki page, but there wasn't anything about auto starting after establishing network connection.
I don't know your particular problem but on XFCE I start several services that need network via autostart desktop entry without worrying about whether the network is there or not. Of course, if the network is not there the service that needs it won't work, but this doesn't stop everything else...