082013

Send an SMS from Unix/Linux Andrew Mallett | Updated August 2013

This script will send an SMS (and email) alert from a Unix/Linux box, based on any predefined event. This is very useful for busy sysadmins who (regrettably) can't spend all their time at the console..

From Unixbox to Mobile

The system uses an email app called SendEmail and an SMS subscription service. SendEmail is written in PERL so you will need to be running PERL on your system.

Installation

For Ubuntu and similar distros, run the following command to install sendEmail..

sudo apt-get install sendemail

Otherwise the archive an be obtained from Caspian's Homepage. After extracting the tarball, copy the single sendEmail script to the /usr/local/sbin directory, which being in the system path, is then invokable from anywhere in the directory tree, just like the native Unix sendmail.

There are various SMS subscription services which basically convert an email to an SMS message. I use messagenet.com.au who offer an inexpensive and reliable service.

Bringing it all together

The sendEmail function comes with clearly documented Usage Instructions and examples. Here is one of my own shell scripts sms.sh, used for sending off an SMS-email..

#!/bin/sh
#Andy's Emailer using sendEmail

sendEmail -f sender@domain.com \
          -t 04091234567@messagenet.com.au \
          -s sendmail.yoursmtpserver.com \
          -xu secure_smtp_username \
          -xp secure_smtp_passwd \
          -u "66666 Test SMS" \
          -m "This is a test SMS from your Unix Server.." \

In the above example, sendEmail is invoked with the following parameters:

-f  (from:) - specifies the sender's email address
-t  (to:) - destination address, in this case a mobile number at messagenet.com.au
-s  (smtp) - name of SMTP server
-xu (secure username) - authorised username for secure SMTP servers
-xp (secure passwd) - authorised user's password for secure SMTP servers
-u   (subject) - subject line
-m   (message) - message

Note that the subject line contains the number, 66666. This is the password number for the messagenet service, which must be included in the subject line or message body. It is used to prevent SMS spamming and other abuse of the SMS-email system and is stripped out of the final SMS message.

Don't forget to make the original sendEmail PERL script and your own email sending script executable before running them.

This system is basically the same as sending any old email and so requires the use of a bona fide SMTP Server to send the email out. I use one of my web hosting service's Mail Servers but your ISP's default Mail Server should do the job.

Although the Usage Instructions imply the -xu and -xp switches are not normally used (listed, amusingly, under the Paranormal section), I would suggest that most mail servers these days use secure SMTP to reduce spam and will require an authorised user's credentials to send an email. This system can of course be used to send normal emails too.

Back

Comments (2)

This is awesome now i can send alerts from my servers at any time for warning :-D
#1 - Dreyfus - 02/04/2014 - 02:32
SMS script
There are free providers too they just include an ad in the message.
#2 - HAZARDOUS - 12/13/2014 - 05:41
Name
E-mail (Will not appear online)
Homepage
Title
Comment
;-) :-) :-D :-( :-o :-O B-) :oops: :-[] :-P
To prevent automated Bots form spamming, please enter the text you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
»
This comment form is powered by GentleSource Comment Script. It can be included in PHP or HTML files and allows visitors to leave comments on the website.

PHP Script   Throwaway Email   Disposable Email