Difference between revisions of "Telenor SMS"
From ivc wiki
Jump to navigationJump to search
Line 7: | Line 7: | ||
#!/bin/sh | #!/bin/sh | ||
# | |||
# Telenor Send SMS Script - by ivc | # Telenor Send SMS Script - by ivc | ||
# | # | ||
# 2009-02-03: Initial version | |||
# | |||
# Settings | # Settings | ||
username=<your telenor cellnumber> | username=<your telenor cellnumber> | ||
Line 15: | Line 19: | ||
# | # Rest of the script, no editing needed | ||
tonumber=$1 | tonumber=$1 | ||
message=`echo $@|sed -e 's/'"$tonumber"' //g' -e 's/ /%20/g'` | message=`echo $@|sed -e 's/'"$tonumber"' //g' -e 's/ /%20/g'` | ||
cookiesfile=telenor_cookies.txt | cwd=`dirname $0` | ||
cookiesfile=$cwd/telenor_cookies.txt | |||
echo -e "\n Telenor Send SMS Shell Script - by ivc\n" | echo -e "\n Telenor Send SMS Shell Script - by ivc\n" | ||
Line 31: | Line 36: | ||
# Login | # Login | ||
login=`wget | 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` | --post-data="j_username=$username&j_password=$password&fromweb=undefined" https://telenormobil.no/minesider/login.do` | ||
Line 39: | Line 45: | ||
toomanyattempt=`echo $login|grep "sperret"` | toomanyattempt=`echo $login|grep "sperret"` | ||
if [ -n "$loginsuccessful" ]; then echo -e " Successfully logged in | 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; | 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 | else echo -e " Failed to log in, check the username and password!\n"; exit; fi | ||
Line 45: | Line 51: | ||
# Send SMS | # Send SMS | ||
sendsms=`wget | 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` | --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 | ||
sendsmssuccessful=`echo $sendsms|grep "$ | sendsmssuccessful=`echo $sendsms|grep "Meldingen er sendt"` | ||
if [ -n "$sendsmssuccessful" ]; then echo -e " Message sent!\n"; 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 "$ | if [ -n "$smsleftcount" ]; then echo -e "\n Number of free web SMS messages left: $smsleftcount\n"; fi | ||
Line 62: | Line 79: | ||
== References == | == References == | ||
* [http://www.telenor.no/mobil/ Telenor Mobil] | * [http://www.telenor.no/mobil/ Telenor Mobil] | ||
* [http://stackoverflow.com/questions/242538/unix-shell-script-find-out-which-directory-the-script-file-resides] dirname - Find out which directory the script file resides] | |||
* [http://www.allinterview.com/showanswers/13077.html awk - Two strings, extract part] |
Revision as of 23:15, 3 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!\n"; 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.
References
- Telenor Mobil
- [1] dirname - Find out which directory the script file resides]
- awk - Two strings, extract part