Openwrt配合smstools3推送短信

安装smstools3,并编辑/etc/smsd.conf

devices = GSM1
incoming = /var/spool/sms/incoming
outgoing = /var/spool/sms/outgoing
checked = /var/spool/sms/checked
failed = /var/spool/sms/failed
sent = /var/spool/sms/sent
receive_before_send = no
autosplit = 3
logfile = 1
loglevel = 5
eventhandler = /root/pushsms

# Uncomment (and edit) this section to allow smsd to start:
#
[GSM1]
init = AT+CPMS="ME","ME","ME"
device = /dev/ttyUSB2
incoming = yes
#pin = 0000
baudrate = 115200

创建文件/root/pushsms,替换下划线的变量,并赋予可执行权限

#!/bin/sh

if [ "$1" == "RECEIVED" ]; then
  from=$(grep "From:" $2 | awk -F ': ' '{printf $2}')
  sent=$(grep "Sent:" $2 | awk -F ': ' '{printf $2}')
  received=$(grep "Received:" $2 | awk -F ': ' '{printf $2}')
  alphabet=$(grep "Alphabet:" $2 | awk -F ': ' '{printf $2}')

  if [ "$alphabet" = "UCS2" ]; then
    content=$(sed -e '1,/^$/ d' < "$2" | iconv -f UNICODEBIG -t UTF-8)
  else
    content=$(sed -e '1,/^$/ d' < "$2")
  fi

  text=$(cat <<EOF
【短信转发】
${content}
发件人: ${from}
EOF
)

  curl -d "text=${text}" "__URL__"
fi