Improving Bash service to start/stop torrents by monitoring public IP
0
votes
1
answer
114
views
I am looking for feedback on my solution to monitor my public ip for torrenting.
The public IP is checked against icanhazip. If the vpn is not active, pause all torrents. If vpn is active, then a check for any torrents that are downloading is made. If at least one is downloading then a all are started/queued, otherwise nothing is done because all torrents are paused.
#!/bin/bash
#Torrent/VPN Watch Service
while :
do
ip=$(curl -s icanhazip.com)
pchk=$(transmission-remote -tall -i | grep -a State | grep -ao Down | head -1)
if [ "$ip" = xxx.xxx.xxx.xxx ] ; then
date
echo "WARNING! The Current IP is: $ip"
echo "Torrents are being stopped!"
echo "Openvpn is being restarted!"
echo
sleep 5
/usr/bin/transmission-remote -tall --stop > /dev/null 2>&1
pkill -9 screen
screen -wipe > /dev/null 2>&1
pkill -9 openvpn
screen -dmS openvpn /usr/sbin/openvpn /usr/local/sbin/tvw/file.ovpn
fi
if [ "$pchk" = "Down" ] ; then
date
echo "The Current IP is: $ip"
echo "Torrents are active!"
echo
sleep 5
/usr/bin/transmission-remote -tall --start > /dev/null 2>&1
else
date
echo "Current IP: $ip"
echo "All torrents are paused."
echo
sleep 5
fi
done
exit
Asked by Cody Millard
(11 rep)
Oct 27, 2022, 02:16 AM
Last activity: Oct 28, 2022, 09:59 PM
Last activity: Oct 28, 2022, 09:59 PM