1GAMMU-SMSD-RUN(7) Gammu GAMMU-SMSD-RUN(7)
2
3
4
6 gammu-smsd-run - documentation for RunOnReceive directive
7
9 Gammu SMSD can be configured by RunOnReceive directive (see gammu-sms‐
10 drc for details) to run defined program after receiving every message.
11 It can receive single message or more messages, which are parts of one
12 multipart message.
13
14 This parameter is executed through shell, so you might need to escape
15 some special characters and you can include any number of parameters.
16 Additionally parameters with identifiers of received messages are
17 appended to the command line. The identifiers depend on used service
18 backend, typically it is ID of inserted row for database backends or
19 file name for file based backends.
20
21 Gammu SMSD waits for the script to terminate. If you make some time
22 consuming there, it will make SMSD not receive new messages. However to
23 limit breakage from this situation, the waiting time is limited to two
24 minutes. After this time SMSD will continue in normal operation and
25 might execute your script again.
26
27 NOTE:
28 All input and output file descriptors are closed when this program
29 is invoked, so you have to ensure to open files on your own.
30
32 New in version 1.28.0.
33
34
35 Program is executed with environment which contains lot of information
36 about the message. You can use it together with NULL service (see
37 gammu-smsd-null) to implement completely own processing of messages.
38
39 Global variables
40 SMS_MESSAGES
41 Number of physical messages received.
42
43 DECODED_PARTS
44 Number of decoded message parts.
45
46 PHONE_ID
47 New in version 1.38.2.
48
49
50 Value of PhoneID. Useful when running multiple instances (see
51 smsd-multi).
52
53 Per message variables
54 The variables further described as SMS_1_... are generated for each
55 physical message, where 1 is replaced by current number of message.
56
57 SMS_1_CLASS
58 Class of message.
59
60 SMS_1_NUMBER
61 Sender number.
62
63 SMS_1_TEXT
64 Message text. Text is not available for 8-bit binary messages.
65
66 SMS_1_REFERENCE
67 New in version 1.38.5.
68
69
70 Message Reference. If delivery status received, this variable
71 contains TPMR of original message
72
73 Per part variables
74 The variables further described as DECODED_1_... are generated for each
75 message part, where 1 is replaced by current number of part. Set are
76 only those variables whose content is present in the message.
77
78 DECODED_1_TEXT
79 Decoded long message text.
80
81 DECODED_1_MMS_SENDER
82 Sender of MMS indication message.
83
84 DECODED_1_MMS_TITLE
85 title of MMS indication message.
86
87 DECODED_1_MMS_ADDRESS
88 Address (URL) of MMS from MMS indication message.
89
90 SEE ALSO:
91 faq-mms-download
92
93 DECODED_1_MMS_SIZE
94 Size of MMS as specified in MMS indication message.
95
97 Activating RunOnReceive
98 To activate this feature you need to set RunOnReceive in the gammu-sms‐
99 drc.
100
101 [smsd]
102 RunOnReceive = /path/to/script.sh
103
104 Processing messages from the files backend
105 Following script (if used as RunOnReceive handler) passes message data
106 to other program. This works only with the gammu-smsd-files.
107
108 #!/bin/sh
109 INBOX=/path/to/smsd/inbox
110 PROGRAM=/bin/cat
111 for ID in "$@" ; do
112 $PROGRAM < $INBOX/$ID
113 done
114
115
116
117 Invoking commands based on message text
118 Following script (if used as RunOnReceive handler) executes given pro‐
119 grams based on message text.
120
121 #!/bin/sh
122
123 # Check for sender number
124 if [ "$SMS_1_NUMBER" != "+420123456789" ] ; then
125 exit
126 fi
127
128 # Handle commands
129 case "$SMS_1_TEXT" in
130 "DMS A")
131 /usr/bin/dms-a
132 ;;
133 "DMS B")
134 /usr/bin/dms-b
135 ;;
136 esac
137
138
139 Passing message text to program
140 Following script (if used as RunOnReceive handler) passes message text
141 and sender to external program.
142
143 #!/bin/sh
144 PROGRAM=/bin/echo
145 for i in `seq $SMS_MESSAGES` ; do
146 eval "$PROGRAM \"\${SMS_${i}_NUMBER}\" \"\${SMS_${i}_TEXT}\""
147 done
148
149
150 Passing MMS indication parameters to external program
151 Following script (if used as RunOnReceive handler) will write informa‐
152 tion about each received MMS indication to the log file. Just replace
153 echo command with your own program to do custom processing.
154
155 #!/bin/sh
156 if [ $DECODED_PARTS -eq 0 ] ; then
157 # No decoded parts, nothing to process
158 exit
159 fi
160 if [ "$DECODED_1_MMS_ADDRESS" ] ; then
161 echo "$DECODED_1_MMS_ADDRESS" "$DECODED_1_MMS_SENDER" "$DECODED_1_MMS_TITLE" >> /tmp/smsd-mms.log
162 fi
163
164
165 Processing message text in Python
166 Following script (if used as RunOnReceive handler) written in Python
167 will concatenate all text from received message:
168
169 #!/usr/bin/env python
170 from __future__ import print_function
171 import os
172 import sys
173
174 numparts = int(os.environ['DECODED_PARTS'])
175
176 text = ''
177 # Are there any decoded parts?
178 if numparts == 0:
179 text = os.environ['SMS_1_TEXT']
180 # Get all text parts
181 else:
182 for i in range(1, numparts + 1):
183 varname = 'DECODED_%d_TEXT' % i
184 if varname in os.environ:
185 text = text + os.environ[varname]
186
187 # Do something with the text
188 print('Number %s have sent text: %s' % (os.environ['SMS_1_NUMBER'], text))
189
190
192 Michal Čihař <michal@cihar.com>
193
195 2009-2015, Michal Čihař <michal@cihar.com>
196
197
198
199
2001.42.0 Oct 03, 2020 GAMMU-SMSD-RUN(7)