Messente avatar logo

Send notification SMS from command line

- 5 MIN READ - 18 Oct 2012

Ability to send out notification SMS can be most invaluable to system administrators, as it allows to send urgent notifications to admins with ease.

Now there is a very easy way to send out notification SMS from unix command line. Using this guide and example bash script provided below, you can be up and running in less than 10 minutes.

1) Sign up on Messente.com

Go to https://messente.com/ and sign up. This takes up to 1 minute only.

Make sure you also verify your phone number, as this is required to send out SMS. When you skipped the number verification on sign-up flow, then you can add it later by selecting “+ Add Sender” from dashboard Sender selection drop-down menu.

2) Get your API username and password

First you need to know IP address of your server, where you are going to send out text messages. Find out your IP address from command line:

$ echo `curl -s http://automation.whatismyip.com/n09230945.asp`

Now go and get your API username and password from https://messente.com/apiaccount.

3) Get bash script

Save following script to a file, for example sendSMS.sh

#!/bin/bash
#set -x

# Configure this!
MESSENTE_API_USERNAME=00000000000000000000000000000000
MESSENTE_API_PASSWORD=11111111111111111111111111111111

# ---------------------------------------
# Do not modify anything below this line
# ---------------------------------------

if [ ! "$#" -eq 2 ]; then
 echo "ERROR 2 arguments required, $# provided"
 echo "-------------------------------------------------"
 echo "Usage: bash $0 full_phone_number text_message"
 echo "Example: bash $0 4463773683 "This is a test message""
 echo "-------------------------------------------------"
 exit 1
fi
echo -n "Sending SMS..."
curl -o /tmp/send_sms_result 
 -s http://api2.messente.com/send_sms/ 
 -d username=${MESSENTE_API_USERNAME} 
 -d password=${MESSENTE_API_PASSWORD} 
 --data-urlencode "to=$1" 
 --data-urlencode "text=$2"
API_RESULT=$( cat /tmp/send_sms_result | sed 's/( )(.*)/1/' )
API_RESULT_FULL=$( cat /tmp/send_sms_result )
if [ $API_RESULT == "OK" ]; then
 echo " done" 
 exit 0
else
 echo " failed (${API_RESULT_FULL})"
 exit 1
fi

4) Try out your new SMS sending function

You could make this file executable, or just call it directly:

$ bash sendSMS.sh 4463773683 "This is a sample text message"

And you are done! Now you can easily use this script to send out SMS messages

Troubleshooting

First, make sure you edited the script to include your personal API username and password.

Secondly, check the error code from Messente API documentation.

Still having troubles? Contact us development@messente.com and we will help you with it.

Jaanus Rõõmus

Jaanus Rõõmus - CTO

Jaanus is co-founder and CTO of Messente and makes sure its wheels keep spinning and Messente always has a full tank of fuel.

How we help with the regulations of global messaging

26 Jun 2017

Forgoing the need to integrate network operators everywhere you need messages delivered is one of the main advantages of using a global messaging platform. Each connection includes legalities, which includes reviewing several agreements and negotiating terms, and technical tasks, like setting up the connections. So, a single company going through this process on their own would invest a lot of time doing things that have already been done by a messaging platform. Also, the company would end up with higher pricing from network operators, as it has much less traffic.

Lauri Kinkar

Lauri Kinkar

Your sales lab time is scarce

20 Jun 2017

In the series about sales research, I touched upon allocating about 30% of your research time on finding new ideas and possibilities around sales tactics. But how do you actually do it and what do you look for?

Uku Tomikas

Uku Tomikas

An open letter to financial institutions from Yuriy

09 Jun 2017

To the bank, credit card company, and investment firm I work with: I trust you. I really do.

If I didn’t, I wouldn’t put my hard-earned money in your hands. While I’m not a Certified Financial Analyst, I am financially savvy, so I understand that we have a mutually beneficial relationship. From a high-level, banks use the money I deposit to sell loans and invest in other financial instruments. Credit card companies make money on interest charges, other fees, and transaction fees from merchants. The brokerage firm makes money through fees on my account. On the other hand, all I expect is that you are honest about your services, provide returns, and keep my money safe.

Yuriy Mikitchenko

Yuriy Mikitchenko

Start sending messages to

for € N/A

Contact us