I have used gnokii to send sms-messages with several programs. I found that while gnokii is useful for single messages, some sort of queue needed to be utilized when sending/receiving more messages. If queue is not utilized, serial port lockup could (and will) occur when multiple gnokii-programs try to ccess GSM-phone simultaneously. I found that Juraj Bednar has created nice queue for gnokii. However, I couldn't get it to work on my machine (problems with lock-files mostly) and decided to try on my own.


The language I choose was Perl. It's so obious language for small text-processing program like this that it hardly needs any explanation. So I just made a little script that reads queue directory and sends any messages in there. After sending them it copies messages to either "sent" or "fail" folders. I also created small program ( for actually putting the files to queue directories for easy use from procmail and similar programs.

Basic operation is simple. One script handles outgoing messages ( and another script ( handles incoming scripts. These are run by cron once in a while. In addition, there are couple scripts for ease of use and for controlling various things with GSM.

Workflow of send-SMS process

  1. User makes input by either hand or with
  2. script. Input should be in format
    	NUMBER: 012987654
    This text should be then copied to /var/gsm/out - directory ( handles this). Multiple numbers should be separated by comma (,).
  3. when ever is ran, it cheks /var/gsm/out for outgoing messages. If there is one or more messages, it sends them to phone by calling Gnokii-software.
  4. If sending is successful, sent message is copied to /var/gsm/sent-directory for easy access at later times. If sending failed, SMS is copied to /var/gsm/fail -directory and e-mail is sent to "fail-address" that's defined in

Workflow of get-SMS process

  1. Phone gets SMS
  2. is run by cron. It checks if phone has any incoming messages. If it has, it gets them and saves them to /var/gsm/in - directory. It also deletes messages from phone.
  3. is a script that handles possible SMS-commands to various things like gsm-controlled sauna or similar... So when ever I send message with "SAUNA TILA" in the text to my computer, it responds with temperature readings from outside and from our sauna. This is handled in that is also run by cron.
  4. If message does not contain valid keyword (defined in, it stays in /var/gsm/in
  5. If keyword is found, it's handled in appropriate subroutine in


Installation is pretty straightforward.

  1. Make world-writable directories under /var/gsm:
    	total 28
    	drwxrwxrwx    2 henkka     henkka         4096 Dec  3 17:15 fail
    	drwxrwxrwx    2 henkka     henkka         4096 Dec 13 14:06 in
    	drwxrwxrwx    2 henkka     henkka         4096 Dec 13 14:06 in.handled
    	drwxrwxrwx    2 henkka     henkka         4096 Dec 13 14:07 out
    	drwxrwxrwx    2 henkka     henkka        12288 Dec 13 14:07 sent
    mkdir /var/gsm
    mkdir /var/gsm/fail
    mkdir /var/gsm/in
    mkdir /var/gsm/in.handled
    mkdir /var/gsm/out
    mkdir /var/gsm/sent
    chmod -R a+rwx /var/gsm
  2. Copy scripts to some directory. I have used /usr/local/bin
  3. Make sure scripts are executable:
    chmod a+rx /usr/local/bin/
    chmod a+rx /usr/local/bin/
    chmod a+rx /usr/local/bin/
    chmod a+rx /usr/local/bin/
  4. Edit crontab with crontab -e (or edit directly /etc/crontab) and put following entries to it:
    	0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/bin/ 2> /dev/null
    	2,7,13,17,22,27,32,37,42,47,52,57 * * * * /usr/local/bin/
    	* * * * * /usr/local/bin/ 2>/dev/null
    So that means and are run at 5 minute differences between each other. This is because only one script can call gnokii at a time (due the serial-port lockup).
  5. Test your setup by calling

    echo "First test SMS"|/usr/local/bin/ 0129876543

    (Of course, replace number with your own number...
    If you look to /var/gsm/out, there should be one message:

    	[henkka@kilpikonna gsmqueue]$ ls /var/gsm/out/
    	[henkka@kilpikonna gsmqueue]$ cat /var/gsm/out/sendsms.out.FIOAys 
    	NUMBER: 0129876543
    	First test SMS

    So that message is eventually read by and sent to you ! After that, you can find message from /var/gsm/sent


If something goes wrong, try running programs from commandline. First your should be able to call with

echo "First test SMS"|/usr/local/bin/ 0129876543

This should copy your message to /var/gsm/out. Then you can try running by hand:


Procmail-setup for sending sms by e-mail

Edit your ~/.procmailrc and put following line to it:

:0 c
* ^From.*myself
* ^Subject.*sendsms
|formail  -I "" | /usr/local/bin/

That way, any messages sent from "myself" with subject containing "sendsms" are copied to script. Messages should be in

NUMBER: 12309987645



Simple script to send sms with web-interface. Simply create a file "sms.cgi" with following contents:

#!/usr/bin/perl use CGI qw/:standard/; my $q = new CGI; my $text = $q->param('text'); my $number = $q->param('number'); my $smssend = "/usr/local/bin/"; system("echo $text|$smssend $number"); print header, start_html('SMS SENDING VIA WEB'); print "Message sent to $number."; print end_html;

Move the file to your cgi-directory (for example something like /var/www/cgi-bin/) and give it eXecute bit (chmod a+rx sms.cgi).
After that, create a web-page that calls that cgi-script. Create a file "sms.html" in your html-directory (for example something like /var/www/html/):
<form action="/cgi-bin/sms.cgi">

Text:<textarea name="text" rows="5" cols="20"></textarea>
Number:<input type="text" name="number"><br>
<input type="submit" value="send">

After that, you can try surfing "http://localhost/sms.html"...


Released under GPL. (c) Henry Palonen, 2001,