Smstools¶
apt install smstools
apt install recode
# cat /etc/udev/rules.d/49-gsm_model.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", ATTR{idProduct}=="1506", GROUP="dialout"
SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", ATTR{idProduct}=="1506", RUN+="/sbin/modprobe usbserial vendor=0x12d1 product=0x1506"
# cat /etc/udev/rules.d/50-gsm_model.rules
KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1506", ENV{MODEM_ID}="12d1:1506"
ENV{MODEM_ID}=="12d1:1506", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", ATTRS{bInterfaceNumber}=="00", SYMLINK+="modem0"
udevadm control --reload-rules && udevadm trigger
# cat /etc/smsd.conf
#
# /etc/smsd.conf
#
# Description: Main configuration file for the smsd
#
user = smsd
group = dialout
devices = GSM1
outgoing = /var/spool/sms/outgoing
checked = /var/spool/sms/checked
incoming = /var/spool/sms/incoming
logfile = /var/log/smstools/smsd.log
infofile = /var/run/smstools/smsd.working
pidfile = /var/run/smstools/smsd.pid
outgoing = /var/spool/sms/outgoing
checked = /var/spool/sms/checked
failed = /var/spool/sms/failed
incoming = /var/spool/sms/incoming
sent = /var/spool/sms/sent
stats = /var/log/smstools/smsd_stats
#loglevel = 7
#delaytime = 10
#errorsleeptime = 10
#blocktime = 3600
#stats = /var/log/smsd_stats
#stats_interval = 3600
#stats_no_zeroes = no
#checkhandler = /usr/local/bin/smscheck
receive_before_send = no
# autosplit 0=no 1=yes 2=with text numbers 3=concatenated
autosplit = 3
# store_received_pdu 0=no, 1=unsupported, 2=unsupported and 8bit, 3=all
#store_received_pdu = 1
#validity = 255
#decode_unicode_text = no
#internal_combine = no
# You can specify here an external program that is started whenever an alarm occurs.
# alarmhandler = /path/to/an/alarmhandler/script
# Specifies what levels start an alarmhandler. You can use value between 2 and 5.
# alarmlevel = 4
# eventhandler = @EVENTHANDLER@
#blacklist = /etc/smstools/blacklist
#whitelist = /etc/smstools/whitelist
#[queues]
# Commented lines are examples for germany
# D1 = /var/spool/sms/D1
# D2 = /var/spool/sms/D2
# O2 = /var/spool/sms/O2
# EPLUS = /var/spool/sms/EPLUS
# QUAM = /var/sppol/sms/QUAM
# MOBILCOM = /var/spool/sms/MOBILCOM
#OTHER = /var/spool/sms/OTHER
#[provider]
# Commented lines are examples for germany
# D1 = 49160, 49170, 49171, 49175, 49151
# D2 = 491520, 49162, 49172, 49173, 49174
# O2 = 49176, 49179, 49159
# EPLUS = 49163, 49177, 49178, 49157
# QUAM = 49150
# MOBILCOM = 49156
#OTHER = 0,1,2,3,4,5,6,7,8,9
#[GSM1]
# init = ATE0+CPMS="SM"+CNMI=2,0,0,2,1
# # Windows: /dev/com1, Solaris: /dev/cua/a, Linux /dev/ttyS0
# device = /dev/ttyS0
# incoming = yes
# queues = OTHER
# You don't need a PIN for mobile phones
# pin = 1111
# mode = new
# smsc = 491722270000
# baudrate = 19200
# rtscts = yes
# cs_convert = yes
# report = no
# memory_start = 1
# primary_memory = memory name
# secondary_memory = memory name
# secondary_memory_max = number
# pdu_from_file = /var/spool/sms/GSM1-PDU
# sending_disabled = no
# decode_unicode_text = no
# internal_combine = no
#
#[GSM2]
#init = ATE0
# Windows: /dev/com2, Solaris: /dev/cua/b, Linux /dev/ttyS1
#device = /dev/ttyS1
#incoming = yes
#queues = OTHER
#You don't need a PIN for mobile phones
#pin = 2222
#mode = new
#smsc = 491710760000
#baudrate = 19200
#rtscts = yes
#cs_convert = yes
#report = no
#memory_start = 1
#primary_memory = memory name
#secondary_memory = memory name
#secondary_memory_max = number
#pdu_from_file = /var/spool/sms/GSM2-PDU
#sending_disabled = no
#decode_unicode_text = no
#internal_combine = no
[GSM1]
device = /dev/modem0
baudrate = 115200
rtscts = no
#init = at+cpms="sm","sm",""
init = AT+CPMS="ME","ME","ME"
init2 = AT+CNMI=1,1,0,2
incoming = high
report = no
mode = new
#send_delay = 20
#pin = 1111
#eventhandler=/usr/local/etc/smsd/sms_event.sh
#regular_run = /usr/local/etc/smsd/gsm1.sh
#regular_run_post_run = /usr/local/etc/smsd/gsm1.sh
#regular_run_cmdfile = /usr/local/etc/smsd/gsm.cmdline
#regular_run_statfile = /usr/local/etc/smsd/gsm.statline
sendsms.sh :
Спойлер...Спойлер...
#!/bin/env sh
# This script send a text sms at the command line by creating
# a sms file in the outgoing queue.
# $1 is the destination phone number.
# $2 is the message text.
# If you leave $2 or both empty, the script will ask you.
# If you give more than 2 arguments, last is taken as a text and
# all other are taken as destination numbers.
# If a destination is asked, you can type multiple numbers
# delimited with spaces.
# Keys for example: "password" and "keke":
# KEYS="5f4dcc3b5aa765d61d8327deb882cf99 4a5ea11b030ec1cfbc8b9947fdf2c872 "
KEYS=""
# When creating keys, remember to use -n for echo:
# echo -n "key" | md5sum
smsd_group="smsd"
# Will need echo which accepts -n argument:
ECHO=echo
case `uname` in
SunOS)
ECHO=/usr/ucb/echo
;;
esac
if ! [ -z "$KEYS" ]; then
printf "Key: "
read KEY
if [ -z "$KEY" ]; then
echo "Key required, stopping."
exit 1
fi
KEY=`$ECHO -n "$KEY" | md5sum | awk '{print $1;}'`
if ! echo "$KEYS" | grep "$KEY" >/dev/null; then
echo "Incorrect key, stopping."
exit 1
fi
fi
DEST=$1
TEXT=$2
if [ -z "$DEST" ]; then
printf "Destination(s): "
read DEST
if [ -z "$DEST" ]; then
echo "No destination, stopping."
exit 1
fi
fi
if [ -z "$TEXT" ]; then
printf "Text: "
read TEXT
if [ -z "$TEXT" ]; then
echo "No text, stopping."
exit 1
fi
fi
if [ $# -gt 2 ]; then
n=$#
while [ $n -gt 1 ]; do
destinations="$destinations $1"
shift
n=`expr $n - 1`
done
TEXT=$1
else
destinations=$DEST
fi
echo "-- "
echo "Text: $TEXT"
ALPHABET=""
if which iconv > /dev/null 2>&1; then
if $ECHO -n "$TEXT" | iconv -t ISO-8859-15 2>&1 | grep "invalid" > /dev/null; then
ALPHABET="Alphabet: UCS"
fi
fi
group=""
if [ -f /etc/group ]; then
if grep $smsd_group: /etc/group >/dev/null; then
group=$smsd_group
fi
fi
for destination in $destinations
do
echo "To: $destination"
TMPFILE=`mktemp /tmp/smsd_XXXXXX`
$ECHO "To: $destination" >> $TMPFILE
[ -n "$ALPHABET" ] && $ECHO "$ALPHABET" >> $TMPFILE
$ECHO "" >> $TMPFILE
if [ -z "$ALPHABET" ]; then
$ECHO -n "$TEXT" >> $TMPFILE
else
$ECHO -n "$TEXT" | iconv -t UNICODEBIG >> $TMPFILE
fi
if [ "x$group" != x ]; then
chgrp $group $TMPFILE
fi
chmod 0660 $TMPFILE
FILE=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $TMPFILE $FILE
chgrp "${smsd_group}" "${FILE}"
chmod 0777 "${FILE}"
done