Difference between revisions of "Telenor SMS"
From ivc wiki
Jump to navigationJump to search
Line 38: | Line 38: | ||
echo -e " Logging in..." | echo -e " Logging in..." | ||
login=`wget --quiet -O- --save-cookies=$cookiesfile --keep-session-cookies \ | login=`wget --quiet -O- --save-cookies=$cookiesfile --keep-session-cookies \ | ||
--post-data="j_username=$username&j_password=$password&fromweb=undefined" https://telenormobil.no/minesider/login.do` | |||
if [ $debug == true ]; then echo "$login"; fi | if [ $debug == true ]; then echo "$login"; fi | ||
Line 53: | Line 53: | ||
echo -e " Sending message..." | echo -e " Sending message..." | ||
sendsms=`wget --quiet -O- --load-cookies=$cookiesfile --keep-session-cookies \ | sendsms=`wget --quiet -O- --load-cookies=$cookiesfile --keep-session-cookies \ | ||
--post-data="toAddress=$tonumber&message=$message&b_send=Send" https://telenormobil.no/ums/compose/sms/process.do` | |||
if [ $debug == true ]; then echo "$sendsms"; fi | if [ $debug == true ]; then echo "$sendsms"; fi |
Revision as of 22:51, 6 February 2009
As a Telenor mobile subscriber, you have the possiblity to send SMS messages via their website. Also, for as long as I can remember, the first 30 messages each month are free.
This is a simple script I made to simplify the process. Instead of having to log-in to post a message, why not do it from the command-line.
Shell Script
The shell script utilizes wget for the web-requests and has some sanitation, error, and debugging functionality. Please feel free to alter the script and give me suggestions for improvements.
#!/bin/sh # # Telenor Send SMS Script - by ivc # # 2009-02-03: Initial version # # Settings username=<your telenor cellnumber> password=<account password> debug=false # Rest of the script, no editing needed tonumber=$1 message=`echo $@|sed -e 's/'"$tonumber"' //g' -e 's/ /%20/g'` cwd=`dirname $0` cookiesfile=$cwd/telenor_cookies.txt echo -e "\n Telenor Send SMS Shell Script - by ivc\n" # Some sanitation if [ -z `which wget` ]; then echo -e " wget binary is missing or is not in the path, install wget and get back to the script.\n"; exit; fi; if [ -z $1 ] || [ -z $2 ]; then echo -e " Missing arguments!\n\n Usage: $0 <number> <text message>\n E.g. $0 99933322 Hi m8, bouldering today?\n"; exit; fi # Debug mesages and setup if [ $debug == true ]; then echo " Sending message \"$message\" to number $tonumber"; fi # Login echo -e " Logging in..." login=`wget --quiet -O- --save-cookies=$cookiesfile --keep-session-cookies \ --post-data="j_username=$username&j_password=$password&fromweb=undefined" https://telenormobil.no/minesider/login.do` if [ $debug == true ]; then echo "$login"; fi loginsuccessful=`echo $login|grep "$username"` toomanyattempt=`echo $login|grep "sperret"` if [ -n "$loginsuccessful" ]; then echo -e " Successfully logged in."; elif [ -n "$toomanyattempt" ]; then echo -e " Server reports too many failed attempts, try again in 30 minutes.\n"; exit; else echo -e " Failed to log in, check the username and password!\n"; exit; fi # Send SMS echo -e " Sending message..." sendsms=`wget --quiet -O- --load-cookies=$cookiesfile --keep-session-cookies \ --post-data="toAddress=$tonumber&message=$message&b_send=Send" https://telenormobil.no/ums/compose/sms/process.do` if [ $debug == true ]; then echo "$sendsms"; fi sendsmssuccessful=`echo $sendsms|grep "Meldingen er sendt"` if [ -n "$sendsmssuccessful" ]; then echo -e " Message sent!"; else echo -e " Failed to send message, try again later.\n"; exit; fi # SMS left count smsleft=`wget --quiet -O- --load-cookies=$cookiesfile --keep-session-cookies https://telenormobil.no/ums/compose/sms.do` if [ $debug == true ]; then echo "$smsleft"; fi smsleftcount=`echo $smsleft|awk -F"web: " '{print $2}'|sed 's/<br\/>/ /g'|cut -d" " -f1` if [ -n "$smsleftcount" ]; then echo -e "\n Number of free web SMS messages left: $smsleftcount\n"; fi # Delete cookies file rm -f "$cookiefile"
Save it as telenor_send_sms.sh and make it executable, chmod +x telenor_send_sms.sh.