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
send.sh      : The script
Here is the example content of the template.txt:
Happy holiday, God bless you.
This is the example of the phones.txt:
+6281100000
+6281100001
Now,the send.sh script:
#!/bin/sh
SMSC="+6281100000"
MSG=`cat template.txt`
for i in `cat phones.txt`; do
 echo "$MSG" | gnokii --sendsms $i --smsc $SMSC
done
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 send.sh
[user@host dir]$ ./send.sh
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.

Comments

spazlon said…
Great post! This is exactly what I was looking for to get me started on a SMS exchange program.

I want to make a program that will send and recieve SMS messages. Basically I want to send a SMS to the machine, then have it interpret what I said (something like "RAID Status") and it will return the output (give me the status of my RAID).

Would gnokii work for something like this?
Unknown said…
Hi Spazlon,

Gnokii has a great feature whereby you can send and receive messages and buffer them into a MySQL database (inbox and outbox separately).

Having done so, you can then create a Windows service or Unix daemon depending upon your environment to check the message queue and act accordingly.

I have done similar things for the data transport to monitor a node where IP network is non-existent.

What you are trying to do is great, however don't forget to apply security measure by responding only to a predefined phone number lists otherwise everyone can abuse your system.