Created
September 18, 2013 12:51
-
-
Save cabrel/6608707 to your computer and use it in GitHub Desktop.
Checks the status of network connections and stops / starts bittorrent sync based on that connectivity. In my case the network I don't want bit torrent sync running, it's first octet is 10.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
IS_INTERNAL=0 | |
IS_WIRELESS_CONNECTED=0 | |
IS_WIRED_CONNECTED=0 | |
IS_BTSYNC_RUNNING=0 | |
PID_FILE=$HOME/.btsync.pid | |
LOG_FILE=$HOME/.btsync-check.log | |
TEST_WIRELESS=`ifconfig wlan0 | grep -i running` | |
TEST_WIRED=`ifconfig eth0 | grep -i running` | |
if [ -z "$TEST_WIRELESS" ]; | |
then | |
IS_WIRELESS_CONNECTED=0 | |
else | |
IS_WIRELESS_CONNECTED=1 | |
fi | |
if [ -z "$TEST_WIRED" ]; | |
then | |
IS_WIRED_CONNECTED=0 | |
else | |
IS_WIRED_CONNECTED=1 | |
fi | |
TEST_NETWORK=`ip addr | grep -iE "inet 10\..*(eth0|wlan0)"` | |
if [ -z "$TEST_NETWORK" ]; | |
then | |
IS_INTERNAL=0 | |
else | |
IS_INTERNAL=1 | |
fi | |
if [ "$IS_INTERNAL" -eq 1 ]; | |
then | |
/usr/lib/btsync-user/btsync-stopper | |
# remove the pid file | |
if [ -f "$PID_FILE" ]; | |
then | |
rm "$PID_FILE" | |
fi | |
else | |
# check to see if task is already running | |
if [ -f "$PID_FILE" ]; | |
then | |
# get current pid | |
CURRENT_PID=$(<"$PID_FILE") | |
#check if pid is running | |
if [! ps -p ${CURRENT_PID} > /dev/null ]; | |
then | |
/usr/lib/btsync-user/btsync-starter | |
fi | |
else | |
/usr/lib/btsync-user/btsync-starter | |
fi | |
fi | |
DATE=`date` | |
echo "${DATE} ${IS_INTERNAL} ${IS_WIRED_CONNECTED} ${IS_WIRELESS_CONNECTED}" >> $LOG_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment