Vpn_reactivate.sh
This is a bash script that I use to check whether a vpn connection is active, reconnect to it if it is lost and stop and restart transmission torrent client accordingly. You can easily modify it, for instance, to kill some other program if your vpn connection is lost.#!/bin/bash ##This script checks if a vpn connection is enabled, stops transmission torrent ##client if the vpn connection is lost, restablishes it and restarts transmission. ##The vpn connection has to be configured through Network Manager nm-applet. ##The script runs forever and has to be stoped pressing CTRL-c ##You will need nmcli, transmission and transmission-remote. ##Name of the VPN connection in NetworkManager: (change this accordingly) IDCONN="Your id connetion as you have in Network Manager" while [ 1 -gt 0 ]; do nmcli con status | grep $IDCONN > /dev/null status=$? sleep 1s if [ $status != 0 ]; then transmission-remote -tall --stop echo "Reconnecting" nmcli con up id $IDCONN sleep 5s nmcli con status | grep $IDCONN > /dev/null status=$? sleep 1s while [ $status !=0 ]; do echo "Reconnecting" nmcli con up id $IDCONN sleep 5s nmcli con status | grep $IDCONN > /dev/null status=$? sleep 1s done transmission-remote -tall --start fi done