How to Queue Torrents in Transmission

Currently there’s no queue features in Transmission. Luckily we can improvise this with the help of transmission-remote, a command based client for transmission, and along with some Linux bash scripting.

Below I have created a simple bash script:

1. Install transmission remote:
sudo apt-get install transmission-cli

2. Copy the script below, and save as my_script_name.sh , (or whatever name you prefer, but note the .sh extension).

#!/bin/sh
 
# *************
# Configuration
REMOTE="/usr/bin/transmission-remote"
USERNAME="my_username"
PASSWORD="my_password"
MAXDOWN="max_number_of_torrent_to_download"
MAXACTIVE="max_active_torrent"
CONFIG="/my_location_to_transmission_config_file/settings.json"
TRANSOPTS="127.0.0.1:my_port_number"
 
# *************
# Set-up variables
CMD="$REMOTE $TRANSOPTS --auth $USERNAME:$PASSWORD"
LOGCMD="/usr/bin/logger -t transmission-queue "
MAXRATIO=$(cat $CONFIG | grep "ratio-limit":)
MAXRATIO=${MAXRATIO#*"ratio-limit": }
MAXRATIO=${MAXRATIO%*, }
 
# *************
# deal with downloads
DOWNACTIVE="$($CMD -l | tail --lines=+2 | grep -v 100% | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will Verify | wc -l)"
if [ $MAXDOWN -lt $DOWNACTIVE ]; then
    DOWNTOSTOP="$($CMD -l | tail --lines=+2 | grep -v 100% | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will Verify | tail -n $(expr $DOWNACTIVE - $MAXDOWN) | awk '{ print $1; }')"
    for ID in $DOWNTOSTOP; do
        NAME="$($CMD --torrent $ID --info | grep Name:)"
        $LOGCMD "< <> /dev/null 2>&1
    done
else
    [ $(expr $MAXDOWN - $DOWNACTIVE) -gt 0 ] && (
    DOWNINACTIVE="$($CMD -l | tail --lines=+2 | grep -v 100% | grep Stopped | wc -l)"
    [ $DOWNINACTIVE -gt 0 ] && (
        DOWNTOSTART="$($CMD -l | tail --lines=+2 | grep -v 100% | grep Stopped | head -n $(expr $MAXDOWN - $DOWNACTIVE) | awk '{ print $1; }')"
        for ID in $DOWNTOSTART; do
            NAME="$($CMD --torrent $ID --info | grep Name:)"
            $LOGCMD ">>> $ID: ${NAME#*Name: }"
            $CMD --torrent $ID --start >> /dev/null 2>&1
        done
        )
    )
fi
# Then deal with total active
ACTIVE="$($CMD -l | tail --lines=+2 | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will Verify | wc -l)"
if [ $MAXACTIVE -lt $ACTIVE ]; then
    TOSTOP="$($CMD -l | tail --lines=+2 | grep 100% | grep -v Stopped | grep -v Verifying | grep -v Will Verify | tail -n $(expr $ACTIVE - $MAXACTIVE) | awk '{ print $1; }')"
    for ID in $TOSTOP; do
        NAME="$($CMD --torrent $ID --info | grep Name:)"
        $LOGCMD "< <> /dev/null 2>&1
    done
else
    [ $(expr $MAXACTIVE - $ACTIVE) -gt 0 ] && (
    SEEDINACTIVE="$($CMD -l | tail --lines=+2 | grep 100% | grep Stopped | awk -v ratio=$MAXRATIO '{ if (strtonum(substr($0,52,4)) < ratio) print $0 ;}' | wc -l)"
    [ $SEEDINACTIVE -gt 0 ] && (
        TOSTART="$($CMD -l | tail --lines=+2 | grep 100% | grep Stopped | awk -v ratio=$MAXRATIO '{ if (strtonum(substr($0,52,4)) >> $ID: ${NAME#*Name: }"
            $CMD --torrent $ID --start >> /dev/null 2>&1
        done
        )
    )
fi

Save the script on any location you prefer.

3. Create a cron job to run the script. Open the entry to crontab:
crontab -e

4. Let say you want to run the script 5 minutes, the entry on your cron job should be as below:
*/5 * * * * sh /location_to_my_script/my_script_name.sh

Script courtesy of www.4geeksfromnet.com

Favourite movie quotes

These are my favourite movie quotes, which I could rattle off, anytime:

1. “Adaptation, improvization; your weakness is not your technique.”

2. “I did not choose. I was born, and I am.”

3. “A sad commentary in and of itself.”

As a software developer I’m just waiting for the chance to say the first one during peer review, but so far, not yet. Or perhaps I keep forgetting to do so because my subconscious isn’t allowing me to look stupid. There were, however, a few occasions when I had the opportunity to say the second one – without exception, they were during the “death march” stage of projects in which my colleague and I would miserably ask ourselves how we ended up in the programming profession.

What are your favourite movie quotes, and have you ever used them in real life?

Is blogging dead?

No, but might as well be …

I would say blogging technology is like a human being in his or her mid-forties: mature, established, still able to contribute to society, but decidedly less attractive compared to a certain twenty-year old. (No prizes for guessing who that twenty-year old is.)

One side effect of having amnesia …

… is that you’ll no longer be able to access your email, Facebook, Twitter, and online banking accounts.

Unless, of course, you had clicked “Stay signed in”!

But then you won’t be able to login to your PC as you don’t know the password.

We can imagine Jason Bourne going through hand-to-hand combat, high speed car chases, shootings and explosions, and finally he reaches his former trainer. He puts a gun to Hirsch’s head.

Bourne: What’s my Facebook password? Tell me now!
Dr. Albert Hirsch: b0urne123! Zero for the “o”.

TV Q’s

I’ve been watching a bit more Astro than I usually do these past few weeks. A few questions come to mind:

  1. Is there an episode of Mr. Bean that I haven’t seen, like, 10 times?
  2. Will the scriptwriters of The Simpsons ever run out of ideas?
  3. What is the point of Life After People? By definition, why should we even care?
  4. (Wall-E was shown on the Disney Channel recently) How do we know that EVE is female? But she unmistakeably is one, isn’t she?
  5. Am I the only one who’s bored with reality shows, and who wishes that outlandish car chase sequences with “teba-bo” explosions would make a comeback soon? (While we’re on the subject, Mack trucks ploughing through roadblocks would be also be nice! But cops on motorbikes in tight uniforms should remain tucked away in the past, thanks.)