gammu-smsd RunOnReceive 脚本结果退出状态 2

gammu-smsd RunOnReceive script results exit status 2

我想使用 gammu-smsd RunOnReceive 转发短信。

这是我想要 运行 (/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)会发生什么 - 所以一切正常:

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

求求你帮忙

我遇到了同样的问题,我是这样解决的:

  1. 首先将gammu用户添加到sudoers,没有密码:

    类型:$ sudo visudo

并添加:gammu ALL=(ALL) NOPASSWD: ALL

  1. 然后运行 gammu-smsd 作为根用户:

/etc/init.d/gammu-smsd

USER=gammu 更改为 USER=root

保存它并且不要忘记重新启动守护程序:service gammu-smsd restart

  1. RunOnReceive脚本中在gammu-smsd-inject:

    前面添加sudo

    例如:sudo gammu-smsd-inject TEXT my_tel_num -text "Hello world!"

我希望这对你也有用!

P.S.: 我使用 Gammu 版本 1.31.90.