debit

Télécharger (866 octets)
#!/bin/bash

#Permet d'afficher le débit réseau courant.
#Utilisé par mk_prompt pour l'afficher dans l'invite de commande.

DATA_FILE=/tmp/debit.data

time_stamp1=`cat $DATA_FILE | gawk '{print $1}'`
received1=`cat $DATA_FILE | gawk '{print $2}'`
transmitted1=`cat $DATA_FILE | gawk '{print $3}'`

received2=`cat /proc/net/dev | grep ppp0 | sed "s/:/ /" | gawk '{print $2}'`
transmitted2=`cat /proc/net/dev | grep ppp0 | sed "s/:/ /" | gawk '{print $10}'`

time_stamp2=`date "+%s"`

diff_time=`echo " $time_stamp2 - $time_stamp1" | bc`
if [ $diff_time = 0 ]
then
  diff_time=1
fi

debit_r=`echo " (( $received2 - $received1 ) / $diff_time ) / 1024 " | bc -l | cut -c 1-4`
debit_t=`echo " (( $transmitted2 - $transmitted1 ) / $diff_time ) / 1024 " | bc -l | cut -c 1-4`

echo "R: ${debit_r} T: ${debit_t}"

echo "$time_stamp2 $received2 $transmitted2" > $DATA_FILE