1
0
Fork 0
scripts-admin-quickndirty-p.../script_debit.sh

30 lines
853 B
Bash
Executable file

#!/bin/sh
# Ce script donne la volumétrie d'une interface réseau à intervalle régulier
# (se base sur /proc/net/dev)
FICHIER_PROC=/proc/net/dev
INTERFACE="eth0"
DELAI="10"
OLD_VOLUME_IN=0
OLD_VOLUME_OUT=0
VOLUME_IN=0
VOLUME_OUT=0
while true ; do
VOLUME_IN=$( cat "$FICHIER_PROC" | grep "$INTERFACE:" | sed 's/^[[:space:]]*eth0:\([[:digit:]]\+\)[[:space:]]\+.*/\1/' )
VOLUME_OUT=$( cat "$FICHIER_PROC" | grep "$INTERFACE:" | sed 's/^[[:space:]]*eth0:\([[:digit:]]\+[[:space:]]\+\)\{8\}\([[:digit:]]\+\)[[:space:]]\+.*/\2/' )
if [ "$OLD_VOLUME_IN" -eq "0" ] ; then
echo "Please wait..."
else
printf "%s: %10d o/s reception, %10d o/s emission\n" "$INTERFACE" $(( ( $VOLUME_IN - $OLD_VOLUME_IN ) / $DELAI )) $(( ( $VOLUME_OUT - $OLD_VOLUME_OUT ) / $DELAI ))
fi
OLD_VOLUME_IN=$VOLUME_IN
OLD_VOLUME_OUT=$VOLUME_OUT
sleep "$DELAI"
done