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

时间:2015-01-29 22:16:33

标签: linux bash sms file-permissions gammu

我想使用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 个答案:

答案 0 :(得分:2)

我有同样的问题,我这样解决了:

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

    输入:$ sudo visudo

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

    1. 然后以root用户身份运行gammu-smsd:
    2. /etc/init.d/gammu-smsd

      中的

      USER=gammu更改为USER=root

      保存它,不要忘记重启守护进程:service gammu-smsd restart

      1. RunOnReceive 脚本中,在sudo前添加gammu-smsd-inject

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

      2. 我希望这对你也有用!

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