我想使用gammu-smsd RunOnReceive转发SMS。

这是我要运行(/var/spool/gammu/forward.sh)的脚本,如果我从sudoer或使用sudo -u gammu -g gammu /var/spool/gammu/forward.sh运行它,它会非常完美

#!/bin/bash

SMS_MESSAGES=1

for i in `seq $SMS_MESSAGES`
do
    number="SMS_${i}_NUMBER"
    text="SMS_${i}_TEXT"
    eval "gammu-smsd-inject TEXT my_number_goes_here -text \"${!number}: ${!text}\""
done

这是我遇到的问题:
Thu 2015/01/29 23:08:57 gammu-smsd[2549]: Starting run on receive: /var/spool/gammu/forward.sh IN20150130_000850_00_+37368214400_00.txt
Thu 2015/01/29 23:08:57 gammu-smsd[2154]: Process failed with exit status 2

ls -l /etc/gammu-smsdrc /var/spool/gammu/ /usr/bin/gammu-smsd* 的输出:
-rw-r--r-- 1 root root   457 Jan 29 22:44 /etc/gammu-smsdrc
-rwxrwxrwx 1 root root 14336 Jun 10  2012 /usr/bin/gammu-smsd
-rwxrwxrwx 1 root root 51164 Jun 10  2012 /usr/bin/gammu-smsd-inject
-rwxrwxrwx 1 root root  9972 Jun 10  2012 /usr/bin/gammu-smsd-monitor

/var/spool/gammu/:
total 24
drwxrwxrwx 2 gammu gammu 4096 Jan 28 16:02 error
-rwxrwxrwx 1 gammu gammu  189 Jan 29 22:13 forward.sh
drwxrwxrwx 2 gammu gammu 4096 Jan 29 23:08 inbox
-rw-rw-r-- 1 gammu gammu 3702 Jan 29 23:08 log
drwxrwxrwx 2 gammu gammu 4096 Jan 29 23:07 outbox
drwxrwxrwx 2 gammu gammu 4096 Jan 29 23:07 sent

如果我只做./forward.sh(不是root),会发生什么事-一切都OK:
gammu-smsd-inject[2606]: Created outbox message OUTC20150029_231213_00_my_number_here_sms0.txt
Written message with ID /var/spool/gammu/outbox/OUTC20150029_231213_00_my_number_here_sms0.txt

这是我的/etc/gammu-smsdrc
# Configuration file for Gammu SMS Daemon

[gammu]
port = /dev/ttyUSB0
connection = at

[smsd]
service = files

logfile = /var/spool/gammu/log

debuglevel = 2

commtimeout = 1
sendtimeout = 15
statusfrequency = 0

outboxformat = unicode
transmitformat = unicode

RunOnReceive = /var/spool/gammu/forward.sh

inboxpath = /var/spool/gammu/inbox/
outboxpath = /var/spool/gammu/outbox/
sentsmspath = /var/spool/gammu/sent/
errorsmspath = /var/spool/gammu/error/
ps -fe | grep gammu:
gammu     2154     1  0 23:05 ?        00:00:02 /usr/bin/gammu-smsd --daemon --user gammu --pid /var/run/gammu-smsd.pid
cubie     2644  2403  0 23:20 pts/0    00:00:00 grep gammu

请帮忙

最佳答案

我遇到了同样的问题,并以这种方式解决了这个问题:

  • 首先将gammu用户添加到sudoers中,无需输入密码:
    类型:$ sudo visudo

  • 并添加:gammu ALL=(ALL) NOPASSWD: ALL
  • 然后以root用户身份运行gammu-smsd:

  • /etc/init.d/gammu-smsdUSER=gammu更改为USER=root保存它,别忘了重启守护进程:service gammu-smsd restart
  • 在RunOnReceive脚本中,在sudo前面添加gammu-smsd-inject:
    例如:sudo gammu-smsd-inject TEXT my_tel_num -text "Hello world!"

  • 我希望这也对您有用!
    附注:我使用的是Gammu版本1.31.90。

    08-07 14:26