Szervusztok!
Nemrég elkezdtem 3G-t használni, de céges kártyával, így szükségessé vált, hogy tudjam mennyi volt az adatforgalom. Mivel nem vagyok programozó (nem is értek a számítás technikához), így csak egy egyszerű script-et tudtam összedobni. Gondoltam, ha már az Ubuntu ingyenes, akkor megosztom a világgal, hátha másnak is jól jön.
A számláló:
# /bin/bash
interface="ppp0"
logfile="/home/username/logfile.txt"
if [ ! -e $logfile ]
then touch $logfile
echo 0 > $logfile
echo 0 >> $logfile
fi
temp1="0"
temp2="0"
while [ 1 -gt 0 ]
do
datafull=`cat /proc/net/dev|tr ":" " "|grep $interface|awk '{ print $2 " " $10 }'`
datain=`echo $datafull|awk '{ print $1 }'`
dataout=`echo $datafull|awk '{ print $2 }'`
if [ -z $datain ] && [ $temp1 -gt 0 ]
then
filein1=`cat $logfile|head -n 1|tail -n 1`
filein2=`cat $logfile|head -n 2|tail -n 1`
fileout1=`expr $filein1 + $temp1`
fileout2=`expr $filein2 + $temp2`
echo $fileout1 > $logfile
echo $fileout2 >> $logfile
temp1="0"
temp2="0"
fi
if [ -z $datain ] && [ $temp1 -eq 0 ]
then
datain="0"
dataout="0"
fi
if [ $datain -lt $temp1 ]
then
filein1=`cat $logfile|head -n 1|tail -n 1`
filein2=`cat $logfile|head -n 2|tail -n 1`
fileout1=`expr $filein1 + $temp1`
fileout2=`expr $filein2 + $temp2`
echo $fileout1 > $logfile
echo $fileout2 >> $logfile
temp1=$datain
temp2=$dataout
fi
if [ $datain -gt $temp1 ]
then temp1=$datain
temp2=$dataout
fi
sleep 5
done
5 másodpercenként ellenőrzi a forgalmat és elmenti, ha szükséges.
(Bocsi, csak egy végtelen ciklus jutott eszembe a folyamatos futáshoz)
Az info megjelenítésére:
#!/bin/bash
logfile="/home/username/logfile.txt"
inm="byte"
outm="byte"
in=`cat $logfile|head -n 1|tail -n 1`
out=`cat $logfile|head -n 2|tail -n 1`
inl=`echo $in|wc -c`
outl=`echo $out|wc -c`
if [ $inl -gt 4 ] && [ $inl -lt 8 ]
then
temp=`expr $in / 1024`
in="$temp"
inm="Kb"
fi
if [ $inl -gt 7 ]
then
temp=`expr $in / 1048576`
in="$temp"
inm="Mb"
fi
if [ $outl -gt 4 ] && [ $outl -lt 8 ]
then
temp=`expr $out / 1024`
out="$temp"
outm="Kb"
fi
if [ $outl -gt 7 ]
then
temp=`expr $out / 1048576`
out="$temp"
outm="Mb"
fi
zenity --info --title "3G info" --text="In: $in $inm, out: $out $outm"
A zenity csomagot telepíteni kell a működéséhez!
Üdv: MrNobody