Blackhold

Transferencia de datos

Posted on març 4th, 2010 by Blackhold

Pues ale, acostumbrada a usar SNMP, me he visto obligada a buscar una alternativa para mirar el estado de la transferencia de datos de un servidor al no ser posible la instalación de este servicio :( (no por problemas técnicos, sino diplomáticos! xD)

El scriptillo es un poco cutre pero vale para ello. Usa el comando ifconfig y la transferencia total transmitida por el interfaz y hace un cálculo diferencial.

Espero que sea de ayuda a alguien :)


#!/bin/bash
# Author: Blackhold (http://blackhold.nusepas.com)

#fichero de datos
FILE=/root/scripts/check_hw/rxtx.txt
INTERVAL=60 #en segundos
# añadir al crontab: */1 * * * * root /root/scripts/check_hw/check_eth0.sh

#transferencia en bytes
RXA=`/sbin/ifconfig eth0 |grep “RX bytes” |cut -d “:” -f 2 | cut -d ” ” -f 1`
TXA=`/sbin/ifconfig eth0 |grep “RX bytes” |cut -d “:” -f 3 | cut -d ” ” -f 1`

if [ -e $FILE ]; then
RXO=`tail -1 $FILE |cut -d “;” -f 2 |cut -d “:” -f 2`
TXO=`tail -1 $FILE |cut -d “;” -f 3 |cut -d “:” -f 2`

((RXS=$RXA-$RXO))
((TXS=$TXA-$TXO))

((RXS=$RXS/$INTERVAL/1024))
((TXS=$TXS/$INTERVAL/1024))

#echo “Recv: $RXS kbps”
#echo “Send: $TXS kbps”
else
echo “################# TASA DE TRANSFERENCIA DE DATOS
#################” > $FILE
echo “” >> $FILE
fi

echo “time:`date`;RX:$RXA;TX:$TXA;DOWN:$RXS kbps;UP:$TXS kbps” >> $FILE

This entry was posted on dijous, març 4th, 2010 at 0:45 and is filed under Linux. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

4 Responses to “Transferencia de datos”

Blackholdmarç 20th, 2010 at 17:52

awk ‘{print $1}’

muchas gracias a todos los que me habéis hecho recomendaciones, a ver si algún día encuentro el tiempo y las ganas para empollarme todo el tema de las expresiones regulares que me ahorraría mucho trabajo :D

Leave a Response

9 visitors online now
2 guests, 7 bots, 0 members
Max visitors today: 26 at 02:11 am GMT-2
This month: 31 at 09-01-2010 12:23 pm GMT-2
This year: 87 at 02-15-2010 10:14 am GMT-2
All time: 87 at 02-15-2010 10:14 am GMT-2