# Author: John Jore # Version 0.1 # Init values BSNL=www.data.bsnl.in USERNAME=YOURUSERNAME PASSWORD=YOURPASSWORD COOKIES="/tmp/$(basename $0).$$.bsnl.tmp" TEMP="/tmp/$(basename $0).$$.tmp1.tmp" TEMP2="/tmp/$(basename $0).$$.tmp2.tmp" EMAIL=EMAIL TO SEND NOTIFICATIONS TO Current_Month=`date +%b` Current_Year=`date +%Y` #Not pretty, but it does work.... #The Script # Get the action string curl -c $COOKIES -sS -L http://$BSNL/wps/portal/ -o $TEMP #Parse the Action string ACTION=`cat $TEMP | grep action=\"/wps/portal/ | cut -f 4 -d \"` #Login curl -b $COOKIES -c $COOKIES -sS -L -d "wps.portlets.userid=$USERNAME&password=$PASSWORD&=Log%20in" http://$BSNL/wps/portal/$ACTION -o $TEMP #Parse the URL to get PostPaid Usage ACTION=`cat $TEMP | grep "View Your PostPaid" | cut -f 2 -d \!` # curl -b $COOKIES -c $COOKIES -sS -L http://$BSNL/wps/myportal/!$ACTION!/ -o $TEMP #Parse the output to get the ACTION for selecting Broadband ACTION=`cat $TEMP | grep "action" | cut -f 6 -d \"` #Select Broadband Service curl -b $COOKIES -c $COOKIES -sS -L -d "cmb_UsageSrchForm_ServiceName=Broadband" http://$BSNL$ACTION -o $TEMP #Parse the output to get the ACTION for selecting current month ACTION=`cat $TEMP | grep action | cut -f 6 -d \"` #Select the current month curl -b $COOKIES -c $COOKIES -sS -L -d "hid_UsageSrchForm_ServiceNameOrAccountNumber=service&cmb_UsageSrchForm_ServiceName=Broadband&cmb_UsageSrchForm_ServiceUserId=oc8025371306%40bsnl.in&cmb_UsageDetailsSearch_UsgMnth=$Current_Month-$Current_Year-UnBilled" http://$BSNL$ACTION -o $TEMP #Parse the output to get the ACTION for selecting current month ACTION=`cat $TEMP | grep action | cut -f 6 -d \"` #Select the current month curl -b $COOKIES -c $COOKIES -sS -L -d "hid_UsageSrchForm_ServiceNameOrAccountNumber=service&cmb_UsageSrchForm_ServiceName=Broadband&cmb_UsageSrchForm_ServiceUserId=oc8025371306%40bsnl.in&cmb_UsageDetailsSearch_UsgMnth=$Current_Month-$Current_Year-UnBilled&imageBtn_UsageDetails_Search.x=45&imageBtn_UsageDetails_Search.y=11" http://$BSNL$ACTION -o $TEMP #Extract only the data we care about cat $TEMP | grep "
" -A 87 > $TEMP2 cat $TEMP2 | sed '1,11d' > $TEMP cat $TEMP | sed -n '1,77p' > $TEMP2 #Header for email cat <$TEMP To: $EMAIL Subject: BSNL Usage Stats Content-Type: text/html; charset="us-ascii" EOF #Body of Email cat $TEMP2 >> $TEMP #End of Email echo "" >> $TEMP #Send the email #/usr/sbin/sendmail $EMAIL < $TEMP #For nagios. Will output the usage in GB to a fixed file cat $TEMP | sed -n '78p' > $TEMP2 cat $TEMP2 | cut -f 2 -d \; | cut -f 1 -d "<" > /tmp/bsnl_nagios #Cleanup temp files rm -f $TEMP rm -f $TEMP2 rm -f $COOKIES #All done