Friday, July 13, 2012

Check real bandwidth usage in mobitel sri lanka

#!/bin/bash

if $(gconftool-2 -g /system/http_proxy/use_http_proxy)
then
   export http_proxy="http://$(gconftool-2 -g /system/http_proxy/host):3128"
else
   unset http_proxy
   unset https_proxy
fi

ping -c 1 www.google.com 2>/dev/null >/dev/null
if [[ $? != 0 ]]
then
   zenity --error --text="Error connecting to the server!"
   exit 0;
fi

USER=
PASSWORD=

ACC="username=$USER&password=$PASSWORD"
DATA="select=ing"
COOKEY="/tmp/cookey.$USER"
OUTPUT="/tmp/curl.out"
MYACC="http://selfcare.mobitel.lk/MyAccount"
LOGIN="$MYACC/SubmitLogin.jsp"
DATA_USAGE="$MYACC/DataUsage.jsp"

#echo "curl --head --cookie $COOKEY --cookie-jar $COOKEY --user-agent Mozilla/4.0 --data '$ACC&$DATA' $LOGIN 2>/dev/null >/dev/null"
curl --cookie $COOKEY --cookie-jar $COOKEY --user-agent Mozilla/4.0 --data "$ACC&$DATA" $LOGIN 2>/dev/null >/dev/null
curl --cookie $COOKEY --cookie-jar $COOKEY --user-agent Mozilla/4.0 --data "$ACC&$DATA" $DATA_USAGE -o $OUTPUT 2>/dev/null >/dev/null

UTILIZED="Utilized: $( cat $OUTPUT | grep Utilized -A1 | tail -1 | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' )"
REMAINING="Remaining: $( cat $OUTPUT | grep Remaining -A1 | tail -1 | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' )"
EXCESS="Excess: $( cat $OUTPUT | grep Excess -A1 | tail -1 | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' )"

if [[ $1 == gui ]]
then
   zenity --title "3g Usage in Mb" --info --text=" $UTILIZED \n $REMAINING \n $EXCESS"
else
   echo  $UTILIZED
   echo  $REMAINING
   echo  $EXCESS
fi

No comments:

Post a Comment