Shell script to count number of Mega Bytes used in PPP connections

[ This Blog Was Moved To : http://www.diknows.com ]


Recently I bought, a USB Stick modem that is limited to 500 MB, after the 500 MB each 3 MB = 1 LE. For that I needed to create a counter to check my usage .. not to exceed the 500 Limit. so here it is :

#!/bin/bash

while :;
do t=`pppstats -a | grep -v IN | cut -c -10` ;
echo 'Created By Dino.'
echo '--------------------------------'
echo "Number Of Megabytes used is : ";
echo ${t}/1024/1024 | bc ;
echo '--------------------------------'
sleep 10;
clear;
done

And This is it .. I used till now 166 MBs.. I like that..

======================

New Updates : Lets call it version : 0.2

——————–

#!/bin/bash
###########################################################
#
#        Created By Diaa Mohamed Kasem - Fall 2009
#
###########################################################
#The Main Directory, 
#where ppp counter related data are stored.
mainDir="/root/.pppCounter"
#The Data File where the latest bytes count are stored
dataFile="$mainDir/data.txt"
#The temporary variable holding the ppp IN bytes count
currentValue=0
#Create the main directory if it doesn't exist
mkdir -p $mainDir

# If the data file exists
if [ -f $dataFile ]; then
  # Get the latest saved bytes count 
  currentValue=`cat $dataFile`
  # Inform User
  echo "Latest Used Value is : $(($currentValue/1024/1024))"
fi

# Infinit loop
while :; 
  # Get the current bytes count downloaded 
  # since injecting the stick modem
  do t=`pppstats -a | grep -v IN | cut -c -10` ;
  # Inform User
  echo 'Created By Dino.'
  echo '--------------------------------'
  echo "Number Of Megabytes used is : \
  $(($t/1024/1024 + $currentValue/1024/1024 )) MB";
  echo '--------------------------------'
  # Save the data in the data file
  echo $(($t+$currentValue)) > $dataFile
  # Sleep for 10 seconds
  sleep 10;
  # Clear the screen
  clear;
done

Note : This should run as root

And here is the result till now :

Created By Dino.
——————————–
Number Of Megabytes used is :   97 MB
——————————–

Hope it is helpful..

Advertisements

Suse 11.1 Linux and Egypt Mobinil 3G USB Stick Modem

[ This Blog Was Moved To : http://www.diknows.com ]


Yesterday, I went to Mobinil branch in Tanta, I wanned to buy a USB Stick modem. My issue was that I’m using Linux SUSE 11.1, and I know that the USB Stick modem support is for Windows and Mac OSs only. So, I wanned to know for sure.

There I asked a sales person called “Ahmed Salamah” ( who by the way was really cooporative ). He tested with me the stick modem on my laptop and called a friend of his ( may be a technical support for mobinil, I actually dunno ) who assured him that linux supports USB Stick modem of Type ” HUAWEI E156G” which they sell at Mobinil’s branch. But, it does not support the other model they sell.

So, we tried it several times, but no use. So, we googled for it. I found a link which is that

http://forums.opensuse.org/network-internet/422098-how-configure-usb-modem-opensuse-11-1-a.html

and the technical guy sent us another link on mail, which is this one

http://1337stuff4pro.blogspot.com/2008/05/huawei-e270230-for-linux-os.html

So, I bought the stick modem and said to myself ” Ok, as long as you know for sure that it works for linux, you find a way to make it work, at mobinil they are not the linux gurus”. I bought it and take it back home, tried to find a solution online, and I stuck it into my laptop.

And the surprise was, that the nm-applet gnome Network Manager applet, recognized the connection after a while. And it works fine.

My nm-applet versin in 0.7.0

I guess this is pretty much it.

Notes: This tick modem got a LED, when it is colored Stable Green then it is connected to GPRS
When connected to Light Blue, then it is connected to HSPD (Not sure of the name)  which is better.
When it is connected to Gark Blue, then it is connected to 3G which is the best.

One other thing to note. While we were testing the stick modem on Windows. We found that you can put a limit to your usage in HUAWEI E156G Stick modem in the configuration of the program that ships with it from mobinil. And it got better statistics and configuration than the other modems. So, I suggest that one.

I Dunno about lots of other modems, there may be better modems out there, but between the two types that we tried at mobinil ( the HUAWEI and HTC I guess ), I found this one better.

Posted in LINUX. Tags: , , , , , , . 2 Comments »