User Tools

Site Tools


Send SMS from Shell

Sending SMS can be accomplish via shell with AT commands, thus we can automated sending SMS with shell script.
Ref: Send SMS using AT commands

Using AT commands from shell

Just using shell you can send SMS, I think any modem would work altough I can't verify it because I don't have much modem lying around. By using AT commands, basic modem functionality will be utilized, so no need 3G driver and functionality.

Basically, sequence for send SMS as below:

# determine device modem, we use /dev/ttyUSB0 for this example
echo -e "ATZ\r" >/dev/ttyUSB0 # we need echo parameter -e for interpretation of backslash escapes
echo -e "AT+CMGF=1\r" >/dev/ttyUSB0
echo -e "AT+CMGS=\"123456789\"" >/dev/ttyUSB0 # change 123456789 with SMS destination number
echo -e "Hello this is SMS message from shell\x1A" >/dev/ttyUSB0 # message must be ending with \x1A (ASCII for CTRL+Z)

That's it, SMS should be recieve shortly.

Script for sending SMS

Because SMS can sent from shell, if need it we can automating this process with shell script. Below is a sample to send SMS with shell script:

# Modem device
# Destination mumber
# Message
SMS="Hi, there"
# we need to put sleep 1 to slow down commands for modem to process
echo -e "ATZ\r" >$DEV
sleep 1
echo -e "AT+CMGF=1\r" >$DEV
sleep 1
echo -e "AT+CMGS=\"$DESTNUM\"\r" >$DEV
sleep 1
echo -e "$SMS\x1A" >$DEV
docs/guide-user/advanced/sms-from-shell.txt · Last modified: 2018/03/03 20:13 by bobafetthotmail