linux - Gammu runonreceive 不传递变量

标签 linux shell sms gammu

我想将我的 Rapsberry 配置为 SMS Ping Pong 播放器。所以我安装了 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/

到目前为止,发送短信和接收短信工作正常!

所以我尝试了 runonreceive 的东西。并编写了一个小脚本来获取短信发件人号码和文本。如果文本是“ping”,gammu-smsd 应该将 pong 发送回发件人。

reveivesms.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 的变量不起作用。但我不知道为什么?

最佳答案

使用 gammu-smsd-inject 运行接收以发送短信回复是一项任务。

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

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

问候

关于linux - Gammu runonreceive 不传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37430151/

相关文章:

linux - 使用 Shell 脚本进行数据、时间验证

Ubuntu 中的 Java 类路径问题

bash - 可以检查它是否在调用时后台运行的 Shell 脚本

android - 发送静音短信

android - 从 Activity A 调用方法到 Activity B 时出错

linux - docker 实例可以只连接到一个特定的网络接口(interface)吗?

linux - 在 Linux 中将预定义变量从 shell 脚本传递到 shell 脚本

shell - 在 aws elastic beanstalk 中创建 .ebextensions 文件夹

linux - Bash 脚本忽略 if, then 语句;每次返回相同的结果

Android:Sms Retrieval Api 未从 Intent 获取消息