Skip to content

Instantly share code, notes, and snippets.

@weblogix
Last active August 14, 2021 02:46
Show Gist options
  • Save weblogix/10329853c70df2534dbb4ebc5b1365ce to your computer and use it in GitHub Desktop.
Save weblogix/10329853c70df2534dbb4ebc5b1365ce to your computer and use it in GitHub Desktop.
[qBitorrent stop/start linux commandline]

Start systemctl start fvapp-qbittorrentr6

Stop systemctl stop fvapp-qbittorrentr6

#!/bin/bash

ROUTER_CHECK_HOSTNAME="mooo.com"
NAS_IP=$(curl ifconfig.me)
ROUTER_IP=$(getent hosts ${ROUTER_CHECK_HOSTNAME} | awk '{ print $1 }')
QBITTORRENT_STATUS=$(systemctl status fvapp-qbittorrentr6 | grep 'Active:')

if [[ "$QBITTORRENT_STATUS" =~ .*"active (running)".* && $NAS_IP == $ROUTER_IP ]]; then
        # Kill torrents
        systemctl stop fvapp-qbittorrentr6

elif [[ "$QBITTORRENT_STATUS" =~ .*"inactive (dead)".* && $NAS_IP != $ROUTER_IP ]]; then
        #Start torrents
        systemctl start fvapp-qbittorrentr6
#else
#  echo "everything is ok!"
fi

if [[ "$QBITTORRENT_STATUS" =~ .*"active (running)".* ]]; then
        echo "BT Running - NAS IP - ${NAS_IP}"
else
        echo "BT is down - NAS IP - ${NAS_IP}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment