1

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

# 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:

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

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:

#!/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
  • 415
  • 2
  • 19
  • 1
    Why do you use sudo in the runonreceive? Most likely it is filtering all environment variables.... – Michal Čihař May 25 '16 at 18:53
  • hmm... when i left the sudo.. i get the following log error: Wed 2016/05/25 21:19:09 gammu-smsd[1942]: Starting run on receive: /var/spool/gammu/receivesms.sh IN20160525_211905_00_+49160xxxxxx_00.txt Wed 2016/05/25 21:19:09 gammu-smsd[1896]: Process failed with exit status 139 – swapfile May 25 '16 at 19:20
  • i also checked the permissions. the gammu service runs as root: 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 -rwxrwxrwx 1 root root 401 May 25 09:26 receivesms.sh – swapfile May 25 '16 at 19:27

2 Answers2

2

Getting run on receive to send a sms reply with gammu-smsd-inject was a mission.

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

Regards

QuickPrototype
  • 833
  • 7
  • 18
1

The problem is that sudo doesn't keep environment variables in default configuration, so I suggest you to avoid using sudo in the script. Running SMSD as root is also potential security risk as in case of some error in the SMS decoding, attacker is directly running as root.

So it's way better to run SMSD as user and change permissions for /var/spool/gammu and the modem/phone device accordingly.

If you insist on running SMSD as root, change sudo configuration to keep environment variables, see How to keep Environment Variables when Using SUDO

Community
  • 1
  • 1
Michal Čihař
  • 9,799
  • 6
  • 49
  • 87