Wednesday, September 23, 2009

Mass sending SMS using gnokii

During certain period within a year, we might have to send text messages (festivity greeting) to several friends for example during religious holiday season. Well, writing one template and re-sending text messages through your mobile phone might be OK for 5 or 10 numbers. How about if you have to reply 25 to 50 text messages? Sore thumb :) Gnokii is very good at sending SMS via a GSM/3G/HSDPA modem or GSM phone acting as a modem. The command for sending SMS is simple as long as you have specified a correct device on /etc/gnokiirc. I am using a USB HSDPA modem (Bandluxe C120) so the only changes I made on the /etc/gnokiirc is:
port = /dev/ttyUSB0
model = AT
In order to send mass SMS, I created three files:
template.txt : the message to send no more than 160 characters long.  
phones.txt   : containing the list of phone number the text need to send to      : The script
Here is the example content of the template.txt:
Happy holiday, God bless you.
This is the example of the phones.txt:
Now,the script:
MSG=`cat template.txt`
for i in `cat phones.txt`; do
 echo "$MSG" | gnokii --sendsms $i --smsc $SMSC
Some SIM cards do not set the SMS Center number correctly thus sometimes it does not work. In order to avoid failures, we must specify the SMSC correctly. In my case, I use Telkomsel and the SMSC number is +6281100000. Now, change permission of the script to be executable and execute it. e.g.
[user@host dir]$ chmod 755
[user@host dir]$ ./
You should see some messages scrolling informing whether the process successful or not. Now, no more sore thumb and sore eyes having to write and send SMS from your tiny mobile phone screen.