Archive for March, 2012

Good bye MLDonkey, hello Transmission!

March 27, 2012

Ok, I’ve been a while without updating and althoguh I have some post almost written I wanted to share with you my last piece of code.

As you may remember four years ago I writed about an script which was in charge of setting automatically your MLDonkey rates in order to not overload your bandwith according to the number of clients in your local area network. This script has been running for almost four years and has been a really helpful in achieving the following stats:

more than 3 year sharing; 1.6 T shared!!

more than 3 year sharing; 1.6 T shared!!

Well, after this past years I’ve been using MLDonkey as my bittorrent client but as it doesn’t support magnet links I’ve decided to move on and give Tranmission a try. Installing it has been a piece of cake and as I was really glad with its web-ui I’ve decided to make it my default client and therefore, remake that script in order to work with this new client!

The code its a port from the past one, but you can see it here:

#!/bin/bash
####################################################################################
####################################################################################
# A Transmission (http://www.transmissionbt.com/) script that 
# will vary the download and upload speed limits based on the
# number of hosts currently active on the LAN.
#
# Very usefull when installed in a mediabox that when being the
# only host will set no up/down limits but when a shared connection
# will limit to not overload the network
# 
# Author:
# Jaime Bosque jaboto(at)gmail(dot)com
#
# This script is based in a previous work from the author plus
# - Miguel Mtz (aka) Xarmaz
# - aRDi
# - tazok de esdebian.org
#
# Requirements:
# transmission-remote, transmission, grep, nmap, cron 
#
####################################################################################
####################################################################################

#-----------------------------------------------------------------------------------
# Transmission and network vars.
# -hosts should be 2 if you are using typical network config (router + mediabox) 
#  but may  vary if is in the same box or you have an always-active host
#-----------------------------------------------------------------------------------
transmission=/usr/bin/transmission-daemon
config_file=/home/kets/Transmission-script/settings.json
t_remote=/usr/bin/transmission-remote
user=transmission
pass=transmission
lan=192.168.1
server=localhost
port=9091
log=/home/kets/Transmission-script/transmission_limits.log
hosts=2
#-----------------------------------------------------------------------------------
# Specific rate settins according to the lan usage
# -solo_(up|donw) settings for when just this machine is in lan
# -shared_(up|down) settings for when more that this machine are in lan
#-----------------------------------------------------------------------------------
solo_down=4000
solo_up=4000
shared_down=5
shared_up=5

# Detect if transmission is running
running=`pidof transmission-daemon | wc -l`
pid=`pidof transmission-daemon`

if [ "$running" == "1" ]; then
    # Use nmap to retrieve the number of hosts in lan 
    hosts_up=`nmap -sP $lan.* | grep $lan | wc -l`
    last_read=`tail -n1 $log`
    hosts_up_before=`tail -n1 $log | grep -o -E "H[0-9]+" | grep -o -E [0-9]+`
    if [ -z "$hosts_up_before" ]; then hosts_up_before=0; fi


    # If something has changed in the lan update limits
    # echo "Hosts up $hosts_up  vs $hosts_up_before"
    if [ "$hosts_up" -ne "$hosts_up_before" ]; then
        if [ "$hosts_up" -gt "$hosts" ]; then
            down_limit=$shared_down
            up_limit=$shared_up
        else
            down_limit=$solo_down
            up_limit=$solo_up
        fi
        #echo "Setting limits $down_limit and $up_limit "
        $t_remote $server:$port -n $user:$pass -d $down_limit
        $t_remote $server:$port -n $user:$pass -u $up_limit

        #Log that changes were done!
        echo `date +"%d/%m/%y -- %H:%M"` "S$running H$hosts_up U$up_limit D$down_limit P$pid" >> $log
    fi
else
    # Log that daemon is not running :_(
    echo `date +"%d/%m/%y -- %H:%M"` "Transmission-daemon is not running!" >> $log	

    # Start transmission daemon with the specified config file
    `$transmission -g $config_file`
    echo `date +"%d/%m/%y -- %H:%M"` "Transmission-daemon was lunched!" >> $log
fi	
exit 0

I’ve also created a github repository that you might like to follow for further changes or to know a bit more about the script and settings.

Hope it helps!

¡A correr!

March 15, 2012

La verdad es que desde hace años he salido a correr de manera más o menos intermitente. No se ubicar bien el día en que descubrí que era un deporte que me permitía relajarme y evadirme de todo, recuerdo que he salido a correr casi siempre en días previos a algún evento importante: proyecto fin de carrera, entrevista que decidiría mi futuro…

Correr me relaja, mucha gente dice “yo no corro porque me parece aburridísimo” y la verdad, que yo después de una sesión de una hora corriendo suelo ser incapaz de decir en qué he pasado el tiempo, a veces me surgen ideas que consigo recordar pero otras muchas son pensamientos momentáneos, podría compararlo a cuando duermo y luego me acuerdo de muy pocos sueños y sin embargo, sé que han pasado ocho horas. Hace unos meses, una de estas ideas que surgieron porque sí fue la siguiente: ¿podría correr una maratón?

Y como mi vida es un poco desastre últimamente y no tenía nada claro pensé, bueno, por lo menos voy a fijarme un objetivo, ¡correr una maratón!. Desde entonces he estado entrenando con bastante frecuencia aunque no sé si lo suficiente para llegar a correr la maratón, me propuse hacerlo el día 12 de diciembre de 2012, doce días arriba, doce abajo.

De momento, hace ya casi un mes, corrí por primera vez una distancia inimaginable para mí: ¡23 kms! Al principio fue todo estupendamente, pero cuando llevaba ya una hora y me encontraba a unos 10 kilómetros del punto de llegada mi pierna derecha empezó a flaquear, la ignoré, luego vino la izquierda y también la ignore. Al final conseguí llegar, reventado, con los tendones superiores de los cuádriceps muy doloridos, con dos uñas de los pies negras… ¡pero lo conseguí!

La hazaña la reflejé con el GPS del móvil que, por desgracia, no grabó los dos primeros kilómetros más o menos:

Media maratón

Media maratón

Distancia total: 21,39 km
Tiempo en movimiento: 1:55:14
Velocidad de avance media: 11,13 km/h (6,9 millas/h)
Velocidad máxima: 16,20 km/h (10,1 millas/h)
Elevación mínima: 79 m (259 pies)
Elevación máxima: 302 m (992 pies)
Incremento de elevación: 402 m (1318 pies)
Grado máximo: -4 %
Grado mínimo: -9 %
Fecha de grabación: 11/02/12 11:33

En unos meses os cuento sin conseguí mi objetivo del año 🙂