Notify me if no VPN is active

I have blogged about ensuring you connect to a VPN when connecting to certain wi-fi networks. I have also blogged about connecting to a VPN when the computer boots. Both of those methods have merit, but also some inconveniences, like conflicting VPN profiles, or difficulty connecting on boot (before the password keyring for the VPN password is ready), etc.

I simplified my solution quite a bit, and I made it more resilient.

One of the things I said in my previous post I want a GNOME notification when not connected to VPN :

I would like to have a GNOME extension that pops a notification whenever I am not connected to a VPN.

Today I made that myself, and it was quite simple.

I started making a script that checks if there is a VPN network interface active. If not, then it uses notify-send to send a notification. Finally, I run that check every 5 minutes using cron.

The notification

How to do it

This is the script


if [ $(/usr/sbin/ip address|grep "[0-9][0-9]*: tun[0-9][0-9]*: "|wc -l) -eq 0 ]; then
	notify-send -u critical "VPN connection not detected." -a OpenVPN;

Then type crontab -e to edit your cron jobs and add the following line:

*/5 * * * * /bin/bash /home/e0ipso/.config/

Of course, you will need to change /home/e0ipso/.config to the actual location of your script.

That’s it!

Photo by Misha Feshchak on Unsplash

👋 Subscribe!

If you like this content, you might consider subscribing to this site's RSS feed. This is the best way to stay up to date with new content on the site. If you don't know how to subscribe, you can check this tutorial.