swapfile
Posts: 2
Joined: Wed May 25, 2016 7:34 am

Gammu runonreceive doesnt passing variables

Wed May 25, 2016 7:36 am

i want to configure my Rapsberry as a SMS Ping Pong Player. So i installed gammu-smsd and configured the gammu-smsdrc as follows:

Code: Select all

# 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/
so far, sending sms an receiving sms works fine!

So i tried that runonreceive thing. and wrote a small script which should get the sms sender number and the text. and if the text is "ping" gammu-smsd should send pong back to the sender.

reveivessms.sh:

Code: Select all

#!/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 is:

Code: Select all

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])
hmm no message replied...

so i tried without passing Parameters and changed the receivesms.sh to:

Code: Select all

#!/bin/sh
sudo echo Gude Wie | /usr/bin/gammu-smsd-inject -c /etc/gammu-smsdrc TEXT 49160xxxx
and everything is working. Seems, that the variable passing to the receicesms.sh doesn't work. But i have no idea why?

swapfile
Posts: 2
Joined: Wed May 25, 2016 7:34 am

Re: Gammu runonreceive doesnt passing variables

Wed May 25, 2016 7:44 pm

so i have changed the runonreceive command and get rid of the sudo because i got a tip that sudo most likely is filtering all environment variables... then i get the following error in the gammu.log:

Code: Select all

Wed 2016/05/25 21:41:16 gammu-smsd[2443]: Starting run on receive: sh  /var/spool/gammu/receivesms.sh IN20160525_214112_00_+49160xxxxx_00.txt 
Wed 2016/05/25 21:41:16 gammu-smsd[2399]: Process failed with exit status 139
i have also checked the permissions again:

Code: Select all

root 1896 0.1 0.4 26364 4304 ? Ss 21:18 0:00 /usr/bin/gammu-smsd --daemon --user root --pid /var/run/gammu-smsd.pid 
and receivesms.sh is

Code: Select all

 -rwxrwxrwx 1 root root 401 May 25 09:26 receivesms.sh 

UF_DoC
Posts: 49
Joined: Wed Jul 01, 2015 9:00 am

Re: Gammu runonreceive doesnt passing variables

Sun Jul 30, 2017 6:21 pm

For anyone else coming across this issue. I solved it by redirecting stdout and stderr of the gammu-smsd-inject command to /dev/null.

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

Return to “Troubleshooting”