插上3G上网卡
root@raspberrypi:/var/spool/gammu/inbox# lsusb
Bus 001 Device 012: ID 148f:7601 Ralink Technology, Corp. MT7601U Wireless Adapter
Bus 001 Device 014: ID 12d1:140c Huawei Technologies Co., Ltd. E180v
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
可以看到014就是上网卡(不知道型号为啥有点不一样)
root@raspberrypi:/var/spool/gammu/inbox# ls /dev/ttyUSB*
/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB3
root@raspberrypi:/var/spool/gammu/inbox#
然后找挂载的名字,一般来说最后插上的序号就最大,我的是ttyUSB3
如果这里你没发现自己的设备,可能你需要换其他的卡或者自行寻找驱动了。。
接下来配置gammu
sudo apt-get install gammu #安装gammu
gammu-config
#填一下刚才记下的挂载名
#port我用的默认at,可能不同卡需要调试其他的选择
gammu identify
#这里可以看到gammu识别了你的上网卡,电话卡信息
接下来配置gammu的短信daemon
sudo apt-get install gammu-smsd
sudo vim /etc/gammu-smsdrc
# Configuration file for Gammu SMS Daemon
# Gammu library configuration, see gammurc(5)
[gammu]
# Please configure this!
port = /dev/ttyUSB3 #改自己的
connection = at
# Debugging
#logformat = textall
# SMSD configuration, see gammu-smsdrc(5)
[smsd]
RunOnReceive = /var/spool/gammu/auto_send_mail.sh #接收到短信便执行此script
service = files
logfile = syslog
# Increase for debugging information
debuglevel = 0
# Paths where messages are stored
inboxpath = /var/spool/gammu/inbox/ #接收到的短信在这
outboxpath = /var/spool/gammu/outbox/
sentsmspath = /var/spool/gammu/sent/
errorsmspath = /var/spool/gammu/error/
先不管自动执行的插件,我们先测试能否正常接收短信
systemctl start gammu-smsd.service
systemctl enabel gammu-smsd.service
执行后给此电话发个短信,inbox里应该会出现发送的短信,以txt形式来存储
root@raspberrypi:/var/spool/gammu/inbox# ls
IN20170930_101810_00_95378_00.txt IN20191108_142011_00_10655089321279372975_00.txt
IN20170930_110414_00_10690486_00.txt IN20191108_142255_00_10655089321279372975_01.txt
IN20170930_110518_00_106980005858_00.txt IN20191108_160925_00_95395_00.txt
IN20170930_111147_00_106980005858_00.txt IN20191108_201701_00_1069149187561439_00.txt
IN20170930_140453_00_95395_00.txt IN20191108_201701_00_1069149187561439_01.txt
IN20170930_144549_00_95511_00.txt IN20191109_102158_00_95188_00.txt
IN20191107_231609_00_95188_00.txt IN20191109_102731_00_95188_00.txt
IN20191107_232754_00_95188_00.txt IN20191109_160608_00_10655025160989757920_00.txt
IN20191108_122718_00_10655025995188_00.txt IN20191109_160608_00_10655025160989757920_01.txt
IN20191108_124816_00_10010_00.txt IN20191109_204012_00_106550002800077575_00.txt
IN20191108_124816_00_10010_01.txt IN20191109_204350_00_106901336930_00.txt
IN20191108_124816_00_10010_02.txt IN20191109_204619_00_95188_00.txt
IN20191108_140653_00_95395_00.txt IN20191109_204635_00_95188_00.txt
IN20191108_141001_00_95395_00.txt IN20191109_205336_00_95188_00.txt
请参考这篇文章https://blog.csdn.net/zhuyanjun0818/article/details/102992252
现在开始配置自动转发服务
在2中我们看到gammu是支持收到短信后直接执行自定义任务的
具体的文档在https://wammu.eu/docs/manual/smsd/run.html#
其中有各种全局局部变量,包括短信的内容也有,所以我们想直接使用它
注意一句话:. You can use it together with NULL service 所以得先将服务类型改为null 才能使用变量
sudo vim /etc/gammu-smsdrc
。。。。。
[smsd]
RunOnReceive = /var/spool/gammu/auto_send_mail.sh #接收到短信便执行此script
#service = files
service = null
。。。。
配置后记得重启下
systemctl restart gammu-smsd.service
systemctl enable gammu-smsd.service
接下来书写自动转发的script
#!/bin/sh
for i in `seq $SMS_MESSAGES` ; do
echo "\n \
***************** \n \
$SMS_1_TEXT \n \
***************** \n \
" |mutt -s "SMS send by $SMS_1_NUMBER" [email protected]
done
最后的效果图,还不错吧哈哈