summaryrefslogtreecommitdiff
path: root/docs/user/gammu-smsd-run.7
blob: 269a6d30c21b12dc91814ea34b1a1c8402e9b4bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
.TH "GAMMU-SMSD-RUN" "7" "December 22, 2010" "1.28.94" "Gammu"
.SH NAME
gammu-smsd-run \- documentation for RunOnReceive directive
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.\" Man page generated from reStructeredText.
.
.SH DESCRIPTION
.sp
Gammu SMSD can be configured by \fBRunOnReceive\fP directive (see
\fIgammu\-smsdrc\fP for details) to run defined program after receiving
message.
.sp
This parameter is executed through shell, so you might need to escape some
special characters and you can include any number of parameters. Additionally
parameters with identifiers of received messages are appended to the command
line. The identifiers depend on used service backend, typically it is ID of
inserted row for database backends or file name for file based backends.
.sp
Gammu SMSD waits for the script to terminate. If you make some time consuming
there, it will make SMSD not receive new messages. However to limit breakage
from this situation, the waiting time is limited to two minutes. After this
time SMSD will continue in normal operation and might execute your script
again.
.SH ENVIRONMENT
.sp
program is executed with environment which contains lot of information about
the message. You can use it together with NULL service (see
\fIgammu\-smsd\-null\fP) to implement completely own processing of messages.
.SS Global variables
.INDENT 0.0
.TP
.B SMS_MESSAGES
.
Number of physical messages received.
.UNINDENT
.INDENT 0.0
.TP
.B DECODED_PARTS
.
Number of decoded message parts.
.UNINDENT
.SS Per message variables
.sp
The variables further described as \fBSMS_1_...\fP are generated for each physical
message, where 1 is replaced by current number of message.
.INDENT 0.0
.TP
.B SMS_1_CLASS
.
Class of message.
.UNINDENT
.INDENT 0.0
.TP
.B SMS_1_NUMBER
.
Sender number.
.UNINDENT
.INDENT 0.0
.TP
.B SMS_1_TEXT
.
Message text. Text is not available for 8\-bit binary messages.
.UNINDENT
.SS Per part variables
.sp
The variables further described as \fBDECODED_1_...\fP are generated for each message
part, where 1 is replaced by current number of part. Set are only those
variables whose content is present in the message.
.INDENT 0.0
.TP
.B DECODED_1_TEXT
.
Decoded long message text.
.UNINDENT
.INDENT 0.0
.TP
.B DECODED_1_MMS_SENDER
.
Sender of MMS indication message.
.UNINDENT
.INDENT 0.0
.TP
.B DECODED_1_MMS_TITLE
.
title of MMS indication message.
.UNINDENT
.INDENT 0.0
.TP
.B DECODED_1_MMS_ADDRESS
.
Address (URL) of MMS from MMS indication message.
.UNINDENT
.INDENT 0.0
.TP
.B DECODED_1_MMS_SIZE
.
Size of MMS as specified in MMS indication message.
.UNINDENT
.SH EXAMPLES
.SS Activating RunOnReceive
.sp
To activate this feature you need to set \fBRunOnReceive\fP in
the \fIgammu\-smsdrc\fP.
.sp
.nf
.ft C
[smsd]
RunOnReceive = /path/to/script.sh
.ft P
.fi
.SS Processing messages from the files backend
.sp
Following script (if used as \fBRunOnReceive\fP handler) passes
message data to other program. This works only with the \fIgammu\-smsd\-files\fP.
.sp
.nf
.ft C
#!/bin/sh
INBOX=/path/to/smsd/inbox
PROGRAM=/bin/cat
for ID in "$@" ; do
    $PROGRAM < $INBOX/$ID
done
.ft P
.fi
.SS Passing message text to program
.sp
Following script (if used as \fBRunOnReceive\fP handler) passes
message text and sender to external program.
.sp
.nf
.ft C
#!/bin/sh
PROGRAM=/bin/echo
for i in \(gaseq $SMS_MESSAGES\(ga ; do
    eval "$PROGRAM \e"\e${SMS_${i}_NUMBER}\e" \e"\e${SMS_${i}_TEXT}\e""
done
.ft P
.fi
.SS Passing MMS indication parameters to external program
.sp
Following script (if used as \fBRunOnReceive\fP handler) will write
information about each received MMS indication to the log file. Just replace
echo command with your own program to do custom processing.
.sp
.nf
.ft C
#!/bin/sh
if [ $DECODED_PARTS \-eq 0 ] ; then
    # No decoded parts, nothing to process
    exit
fi
if [ "$DECODED_1_MMS_ADDRESS" ] ; then
    echo "$DECODED_1_MMS_ADDRESS" "$DECODED_1_MMS_SENDER" "$DECODED_1_MMS_TITLE" >> /tmp/smsd\-mms.log
fi
.ft P
.fi
.SS Processing message text in Python
.sp
Following script (if used as \fBRunOnReceive\fP handler) written
in Python will concatenate all text from received message:
.sp
.nf
.ft C
#!/usr/bin/python
import os
import sys

numparts = int(os.environ[\(aqDECODED_PARTS\(aq])

# Are there any decoded parts?
if numparts == 0:
    print(\(aqNo decoded parts!\(aq)
    sys.exit(1)

# Get all text parts
text = \(aq\(aq
for i in range(1, numparts + 1):
    varname = \(aqDECODED_%d_TEXT\(aq % i
    if varname in os.environ:
        text = text + os.environ[varname]

# Do something with the text
print(\(aqNumber %s have sent text: %s\(aq % (os.environ[\(aqSMS_1_NUMBER\(aq], text))
.ft P
.fi
.SH AUTHOR
Michal Čihař <michal@cihar.com>
.SH COPYRIGHT
2009-2010, Michal Čihař <michal@cihar.com>
.\" Generated by docutils manpage writer.
.\" 
.