Bonjour,
Le script démarre ou arrête transmission-gtk selon que la connexion VPN est up ou down.
C'est une réécriture fortement simplifiée d'un ancien script.
Le script utilise "nmcli".
#
Une ligne est à adapter:
nmcli -p con up uuid 2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8 #Retry the VPN
et peut-être
connected=`nmcli -p c | grep -c "vpn enp1s0"`
################################################################################################
#!/bin/bash
#This program stops a program when your VPN connection is lost then restarts it after the connection is re-established.
#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=`nmcli -p c | grep -c "vpn enp1s0"` #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 10 seconds."
sleep 10 #Give the VPN time to recover so we don't abuse it with reconnection requests.
nmcli -p con up uuid 2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8 #Retry the VPN
fi
done
}
#
#Monitor the VPN and secure VPN dependancies.
connectVPN
date
while true; do
vpnstring=$(nmcli -p c | grep -c "vpn enp1s0") #Define a string to test, 0 = no connection, 1 = connected.
case $vpnstring in
"0")
date
killall "transmission-gtk"
connectVPN
;;
"1")
sleep 5
;;
esac
done
################################################################################################