You are not logged in.

#1 2010-07-17 23:59:59

tawan
Member
Registered: 2010-03-02
Posts: 290
Website

how many users on router? run torrent

I share my router and I have "off-peak" internet time 2am to 8am - I needed a script to see if I am the only user on-line so that my torrents don't suck up the other people's bandwidth...

This works:


#!/bin/bash
# should torrent run?
# using a router shared by a number of people
# If I am the only user or it is off peak time (or other concerns) then decide whether to run torrent
###
#functions
# check who's online
function checkingprocess {
    # start by saying there are zero users
    homeusers="0"
    echo "home users reset to zero"
    # nong (important other user) is not on
    nong="no"
    echo "nong set to no"
    # get the file with MAC addresses of people connected to wireless router
    wget http://192.168.1.1/wlclientview.cmd --http-user=USERNAME --http-password=PASSWORD
    echo "got list"
    mv ~/wlclientview.cmd ~/mybin/whoosonline
    echo "moved list"
    # check if others are on-line
    homeusers=$(grep -c "<tr>" ~/mybin/whoosonline)
    echo "counted $homeusers table rows"
    # remove extra 3 that are not useful
    homeusers=`expr $homeusers - 3`
    echo "that means we have $homeusers users (result -3)"
    # check for special case "nong"
    if grep -q "MAC:OF:USER:NONG" ~/mybin/whoosonline
    then
        # special case - Nong is online too
        nong="nong"
        echo "nong online"
    else
        echo "nong not on line"
    fi
    # report total to text file for conky to display
    echo $homeusers > /home/tawan/mybin/whoosonlinenow
}
# check the time
function timechecker {
    # off-peak internet use between 3 and 6 am
    # actually 3 to 8 but give others a chance early morning from 6
    TIME=`date +%H`
    if [ "$TIME" -ge "02" ]
    then
        mytime="offpeak"
        echo "off peak time?"
        if [ "$TIME" -le "05" ]
        then
            mytime="offpeak"
            echo "off peak time"
        else
            mytime="peak"
            echo "peak time"
        fi
    else
    mytime="peak"
    echo "peak time"
    fi
}
# run
function myrunner {
    ps aux > /tmp/ps.log
    # look in the file for this name to see if it is running
    if grep rtorrent /tmp/ps.log
    then
        appcheck
        if [ "$appkill" -ge "1" ]
        then
            echo "can't run torrent $appkill x web app open"
        else
        echo "torrent already running"
        fi
    else
        echo "run torrent"
        appcheck
        if [ "$appkill" -ge "1" ]
        then
            echo "can't run torrent $appkill x web app open"
        else
            urxvt -g 46x1 -title rtorrent -e rtorrent -o http_capath=/etc/ssl/certs &
        fi
    fi
}
# kill
function mykiller {
    ps aux > /tmp/ps.log
    # look in the file for this name to see if it is running
    if grep rtorrent /tmp/ps.log
    then
        killall rtorrent &
    fi
    echo "kill torrent"
}
# app check
function appcheck {
    appkill="0"
    # skype - kill torrents if skype in use
    myapp="skype"
    appkiller
    # chromium - kill torrents if chromium in use
    myapp="chromium"
    appkiller
    # firefox - kill torrents if firefox in use
    myapp="swiftfox"
    appkiller
}
# app killer
function appkiller {
    if grep $myapp /tmp/ps.log
    then
        mykiller
        echo "killed because of $myapp"
        appkill=`expr $appkill + 1`
    fi
}
# think about it all
function mythinker {
    # in peak time we run if you are the only user
    # in off peak time we run even with other users
    # unless that user is nong and so we kill later
    # always kill if nong is on-line
    if [ "$nong" = "nong" ]
    then
        echo "nong on-line so kill torrent"
        mykiller
    else
        if [ "$mytime" = "offpeak" ]
        then
            echo "....off peak time. Let's run torrent"
            myrunner
        else
            if [ $homeusers -le 1 ]
            then
                echo "....peak time and think only user is you so run torrent"
                myrunner
            else
                echo "....peak time and other users on-line so kill torrent"
                mykiller
            fi
        fi
    fi
}
#end functions
###
###
#loop
while [ 1 ]
    do
    echo "start of loop"
    # run the above functions and loop
    checkingprocess
    timechecker
    mythinker
    echo "done functions, will sleep"
    sleep 20s
    echo "end of loop"
done
#end loop
###

edit : improved

Last edited by tawan (2010-07-25 07:05:20)

Offline

#2 2010-07-19 22:43:35

xenobrain
Member
From: Lodi, CA
Registered: 2006-05-31
Posts: 91

Re: how many users on router? run torrent

Interesting, but why not simply use QoS on your bitorrent ports?

Offline

#3 2010-07-20 08:18:37

tawan
Member
Registered: 2010-03-02
Posts: 290
Website

Re: how many users on router? run torrent

never heard of it. I like playing with my script but happy to throw it in the bin if a simple fix exists.

Offline

#4 2010-07-20 13:54:48

xenobrain
Member
From: Lodi, CA
Registered: 2006-05-31
Posts: 91

Re: how many users on router? run torrent

QoS means Quality of Service.  Basically it reorders or delays packets depending on priority, so that time-sensitive packets always go first, and unimportant packets like bittorrent can be delayed until there is no other traffic being sent.  What I specifally was suggesting here is that your use it to lower the priority of bittorrent traffic, so that you can run it all the time but it only uses spare bandwidth that isn't being used by any other service.

The only catch most routers can only do QoS on inbound connections which is mainly helps latency and not download speeds.  However, if your router is running linux it may have that ability.  Also look for the 'tc' utility or maybe you can install trickle.

This thread has little bit more info.

Last edited by xenobrain (2010-07-20 14:11:50)

Offline

#5 2010-07-20 21:07:11

tawan
Member
Registered: 2010-03-02
Posts: 290
Website

Re: how many users on router? run torrent

that would be good if I have the ability to do it. I will have to look into that.

My next plan was to grep the router page with the traffic stats and look at how much is going on there. This way if other users are idle in the connection I can jump in for a bit of torrenting.

As for QoS I have to see if my router offers that, thanks for the tip.

Offline

Board footer

Powered by FluxBB