Linux Gammu runonreceive不传递变量

Linux Gammu runonreceive不传递变量,linux,shell,sms,gammu,Linux,Shell,Sms,Gammu,我想将我的Rapsberry配置为SMS乒乓球播放器。因此,我安装了gammu smsd,并按如下方式配置gammu smsdrc: # Configuration file for Gammu SMS Daemon # Gammu library configuration, see gammurc(5) [gammu] # Please configure this! port = /dev/ttyUSB3 pin= 4135 connection = at # Debugging log

我想将我的Rapsberry配置为SMS乒乓球播放器。因此,我安装了gammu smsd,并按如下方式配置gammu smsdrc:

# Configuration file for Gammu SMS Daemon

# Gammu library configuration, see gammurc(5)
[gammu]
# Please configure this!
port = /dev/ttyUSB3
pin= 4135
connection = at
# Debugging
logformat = textall

# SMSD configuration, see gammu-smsdrc(5)
[smsd]
RunOnReceive = sudo /var/spool/gammu/receivesms.sh
service = files
pin = 4135
# Increase for debugging information
debuglevel = 1
logfile = /var/spool/gammu/gammu.log
include_smsc = 491722270333

# 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/
到目前为止,发送短信和接收短信都很好

所以我试着用了那个收音器。并写了一个小脚本,应该得到短信发送者的号码和文本。如果文本为“ping”,则gammu smsd应将pong发送回发送方

revievessms.sh:

#!/bin/sh
from=$SMS_1_NUMBER
message=$SMS_1_TEXT
reply=""

if test "$message" = "Ping"; then
    reply="Pong!"
else
    reply="Y U NO PLAY PING PONG?"
fi


sudo echo "$reply" | /usr/bin/gammu-smsd-inject -c /etc/gammu-smsdrc TEXT "$from"
gammu.log是:

Wed 2016/05/25 09:04:31 gammu-smsd[21681]: Received message from: +49160xxxxx
Wed 2016/05/25 09:04:31 gammu-smsd[21681]: Read 1 messages
Wed 2016/05/25 09:04:31 gammu-smsd[21681]: Received IN20160525_090429_00_+49160xxxxxx_00.txt
Wed 2016/05/25 09:04:31 gammu-smsd[21994]: Starting run on receive: sudo /var/spool/gammu/receivesms.sh IN20160525_090429_00_+49160xxxxxx_00.txt 
Wed 2016/05/25 09:04:31 gammu-smsd[21681]: Process finished successfully
Wed 2016/05/25 09:04:53 gammu-smsd[21681]: Found 1 sms to "" with text "Y U NO PLAY PING PONG?" cod 3 lgt 22 udh: t 1 l 0 dlr: -1 fls: -1
Wed 2016/05/25 09:04:53 gammu-smsd[21681]: New message to send: OUTC20160525_090431_00__sms0.smsbackup
Wed 2016/05/25 09:04:53 gammu-smsd[21681]: Message without SMSC, assuming you want to use the one from phone
Wed 2016/05/25 09:05:19 gammu-smsd[21681]: SMS sent on device: "/dev/ttyUSB3" status=500, reference=-1
Wed 2016/05/25 09:05:19 gammu-smsd[21681]: Error getting send status of message: Unknown error. (UNKNOWN[27])
嗯,没有留言回复

因此,我尝试在不传递参数的情况下将receivesms.sh更改为:

#!/bin/sh
sudo echo Gude Wie | /usr/bin/gammu-smsd-inject -c /etc/gammu-smsdrc TEXT 49160xxxx

一切正常。似乎传递给receicesms.sh的变量不起作用。但是我不知道为什么?

问题是sudo没有将环境变量保留在默认配置中,因此我建议您避免在脚本中使用sudo。以root用户身份运行SMSD也存在潜在的安全风险,因为如果SMS解码中出现错误,攻击者将直接以root用户身份运行

因此,最好以用户身份运行SMSD,并相应地更改/var/spool/gammu和调制解调器/电话设备的权限


如果您坚持以root用户身份运行SMSD,请更改sudo配置以保留环境变量,请参见

在接收时运行以发送带有gammu SMSD inject的sms回复是一项任务

对于任何遇到这个问题的人。我通过将gammu-smsd-inject命令的stdout和stderr重定向到/dev/null解决了这个问题

echo "This somehow works" | gammu-smsd-inject TEXT $from > /dev/null 2>&1

关于

为什么在RunnReceive中使用sudo?很可能是过滤了所有的环境变量。。。当我离开sudo的时候。。我收到以下日志错误:Wed 2016/05/25 21:19:09 gammu smsd[1942]:在接收时开始运行:/var/spool/gammu/receivesms.sh 2016/05/25 21:19:09 gammu smsd[1896]:进程失败,退出状态为139i。我还检查了权限。gammu服务以root运行:root 1896 0.1 0.4 26364 4304?Ss 21:18 0:00/usr/bin/gammu-smsd--守护进程--用户根目录--pid/var/run/gammu-smsd.pid和receivesms.sh is-rwxrwx 1根目录401 May 25 09:26 receivesms.sh