GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  GAMMU-SMSD-RUN (7)

NAME

gammu-smsd-run - documentation for RunOnReceive directive \$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]

CONTENTS

Description
Environment
     Global variables
     Per message variables
     Per part variables
Examples
     Activating RunOnReceive
     Processing messages from the files backend
     Invoking commands based on message text
     Passing message text to program
     Passing MMS indication parameters to external program
     Processing message text in Python
Author
Copyright

DESCRIPTION

Gammu SMSD can be configured by RunOnReceive directive (see gammu-smsdrc for details) to run defined program after receiving every message. It can receive single message or more messages, which are parts of one multipart message.

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.

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.

NOTE: All input and output file descriptors are closed when this program is invoked, so you have to ensure to open files on your own.

ENVIRONMENT

New in version 1.28.0.

Program is executed with environment which contains lot of information about the message. You can use it together with NULL service (see gammu-smsd-null) to implement completely own processing of messages.

    Global variables

SMS_MESSAGES
  Number of physical messages received.
DECODED_PARTS
  Number of decoded message parts.

    Per message variables

The variables further described as SMS_1_... are generated for each physical message, where 1 is replaced by current number of message.
SMS_1_CLASS
  Class of message.

SMS_1_NUMBER
  Sender number.
SMS_1_TEXT
  Message text. Text is not available for 8-bit binary messages.

    Per part variables

The variables further described as DECODED_1_... 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.
DECODED_1_TEXT
  Decoded long message text.

DECODED_1_MMS_SENDER
  Sender of MMS indication message.
DECODED_1_MMS_TITLE
  title of MMS indication message.
DECODED_1_MMS_ADDRESS
  Address (URL) of MMS from MMS indication message.
DECODED_1_MMS_SIZE
  Size of MMS as specified in MMS indication message.

EXAMPLES

    Activating RunOnReceive

To activate this feature you need to set RunOnReceive in the gammu-smsdrc.


[smsd]
RunOnReceive = /path/to/script.sh


    Processing messages from the files backend

Following script (if used as RunOnReceive handler) passes message data to other program. This works only with the gammu-smsd-files.


#!/bin/sh
INBOX=/path/to/smsd/inbox
PROGRAM=/bin/cat
for ID in "$@" ; do
    $PROGRAM < $INBOX/$ID
done

    Invoking commands based on message text

Following script (if used as RunOnReceive handler) executes given programs based on message text.


#!/bin/sh

# Check for sender number if [ "$SMS_1_NUMBER" != "+420123456789" ] ; then exit fi

# Handle commands case "$SMS_1_TEXT" in "DMS A") /usr/bin/dms-a ;; "DMS B") /usr/bin/dms-b ;; esac

    Passing message text to program

Following script (if used as RunOnReceive handler) passes message text and sender to external program.


#!/bin/sh
PROGRAM=/bin/echo
for i in `seq $SMS_MESSAGES` ; do
    eval "$PROGRAM \"\${SMS_${i}_NUMBER}\" \"\${SMS_${i}_TEXT}\""
done

    Passing MMS indication parameters to external program

Following script (if used as RunOnReceive 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.


#!/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

    Processing message text in Python

Following script (if used as RunOnReceive handler) written in Python will concatenate all text from received message:


#!/usr/bin/env python
from __future__ import print_function
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))

AUTHOR

Michal Čihař <michal@cihar.com>

COPYRIGHT

2009-2015, Michal Čihař <michal@cihar.com>
Search for    or go to Top of page |  Section 7 |  Main Index


1.37.0 GAMMU-SMSD-RUN (7) February 03, 2016

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.