Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # VPN-BT-Keep-0.2 201901150500 not validated; Also available at http://paste.debian.net/plain/1060550
- # This program stops a program when your VPN connection is lost then restarts it after the connection is re-established.
- # From https://www.debian-fr.org/t/ordonner-a-transmission-de-se-fermer-si-la-connexion-vpn-est-perdue/78326
- # and https://www.wareziens.net/forum/viewtopic.php?id=36487&p=
- UUID_VPN=00589c54-affc-43bd-b252-fee06ded1a89 # UUID_VPN DE SIMULATION À MODIFIER AVEC LE VOTRE # UUID_VPN OF SIMULATION TO MODIFY WITH YOUR
- # nmcli --pretty connection show --active
- # une fois sans avoir activé le vpn et une fois avec le vpn actif.
- # once without having activated the vpn and once with the active vpn.
- # sélectionnez l'identification uuid correspondante au vpn
- # select the uuid identification corresponding to the vpn
- function is_vpn_active() {
- nmcli --terse --fields uuid connection show --active | fgrep --quiet $UUID_VPN && echo 1 || echo 0
- }
- #Attmept a VPN connection until connected
- function connectVPN()
- {
- while : #If the connection is just started or lost, try to reconnect then break out once connected.
- do
- connected=$(is_vpn_active) #Store the current state of the VPN connection.
- if [ "$connected" = "1" ]; then
- echo "connectVPN: vpn up"
- echo ""
- transmission-gtk &
- break
- else
- echo "connectVPN: vpn down, Attempting VPN connection in 20 seconds."
- sleep 20 #Give the VPN time to recover so we don't abuse it with reconnection requests.
- echo "nordvpn connect ..." #Retry the VPN : Ligne de connexion au VPN à adapter. VPN connection line to adapt.
- fi
- done
- }
- #Monitor the VPN and secure VPN dependancies.
- connectVPN
- date
- while true; do
- vpnstring=$(is_vpn_active) #Define a string to test, 0 = no connection, 1 = connected.
- case $vpnstring in
- "0")
- date
- killall transmission-gtk
- connectVPN
- ;;
- "1")
- sleep 1
- ;;
- esac
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement