Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Short Message Service (SMS) is a widely used communication method for sending text messages between mobile phones. While SMS is traditionally associated with mobile devices, it is also possible to send SMS messages from a Linux environment using command-line tools. This can be particularly useful for system administrators who need to send alerts or notifications from servers. In this article, we will explore how to send SMS via the command line in Linux using various tools and services.
Examples:
Using curl
with an SMS Gateway API:
One of the simplest ways to send an SMS from a Linux command line is by using an SMS gateway service that provides an API. Here is an example using the Twilio API.
First, you need to sign up for a Twilio account and get your Account SID, Auth Token, and a Twilio phone number.
#!/bin/bash
# Twilio credentials
ACCOUNT_SID="your_account_sid"
AUTH_TOKEN="your_auth_token"
TWILIO_NUMBER="your_twilio_number"
RECIPIENT_NUMBER="recipient_phone_number"
# Message to send
MESSAGE="Hello, this is a test message from Linux!"
# Send SMS using curl
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/${ACCOUNT_SID}/Messages.json" \
--data-urlencode "To=${RECIPIENT_NUMBER}" \
--data-urlencode "From=${TWILIO_NUMBER}" \
--data-urlencode "Body=${MESSAGE}" \
-u "${ACCOUNT_SID}:${AUTH_TOKEN}"
Save this script as send_sms.sh
, make it executable with chmod +x send_sms.sh
, and run it with ./send_sms.sh
.
Using gammu-smsd
:
gammu-smsd
is a daemon that can be used to send and receive SMS messages using a GSM modem or phone.
First, install gammu
and gammu-smsd
:
sudo apt-get update
sudo apt-get install gammu gammu-smsd
Configure gammu-smsd
by editing the configuration file /etc/gammu-smsdrc
:
[gammu]
device = /dev/ttyUSB0
name = GSM Modem
connection = at
[smsd]
service = files
logfile = /var/log/gammu-smsd.log
debuglevel = 1
RunOnReceive = /path/to/your/script.sh
Create a script to send an SMS:
#!/bin/bash
# Message to send
MESSAGE="Hello, this is a test message from Linux!"
RECIPIENT_NUMBER="recipient_phone_number"
# Send SMS using gammu
echo "${MESSAGE}" | gammu sendsms TEXT "${RECIPIENT_NUMBER}"
Save this script as send_sms_with_gammu.sh
, make it executable with chmod +x send_sms_with_gammu.sh
, and run it with ./send_sms_with_gammu.sh
.