SMS Server Tools 3
 Menu
Basic information:
Additional information:
Support:
Get SMS Server Tools 3:
Additional Options

 Sponsored links

 Search
Custom Search

 Visitor locations
 
 SMS Server Tools 3 Community
Welcome, Guest. The forum is currently read-only, but will open soon. Sun Dec 08, 2024 14:39
SMSTools3 Community » Help and support Bottom

[answered] forward received SMS to group

  This topic is locked

Page:  1

Author Post
Member
Registered:
Nov 2010
Location: Sindh, Pakistan
Hello,


One more thing that i want :

if i sent SMS from my mobile to my smstools number then smstools forward the sms to my desiree group.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Something like this in eventhandler:

#!/bin/bash

if [ "$1" = "RECEIVED" ]; then

  group="
358401111111
358402222222
358403333333
"


  TEXT=`sed -e '1,/^$/ d' < "$2"`

  for recipient in $group
  do
    TMPFILE=`mktemp /tmp/smsd_XXXXXX`
    echo "To: $recipient" >> $TMPFILE
    echo "" >> $TMPFILE
    echo -n "$TEXT" >> $TMPFILE

    FILE=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
    mv $TMPFILE $FILE
  done
fi
 
'bash' Syntax Highlight powered by GeSHi


You could visit this site too: Advanced Bash-Scripting Guide.

Member
Registered:
Nov 2010
Location: Sindh, Pakistan
Topic owner
hElOo Keke,

I want to forward selected msg to particular group.


Like if msg contain ITOPS then forward to desiree group.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
  TEXT=`sed -e '1,/^$/ d' < "$2"`

  if echo -n "$TEXT" | grep "ITOPS" >/dev/null; then

    # Do the actions...

  fi
 
'bash' Syntax Highlight powered by GeSHi


Member
Registered:
Nov 2010
Location: Sindh, Pakistan
Topic owner
Thanks keke,


I am very gratefull to you.

One more fever if i want email to it itops@domain.com

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
mfaisal wrote
One more fever if i want email to it itops@domain.com

Isn't it done in this post: SMS 2 EMAIL?

If you want to get email address from the SMS, you can use the code like this:

  TEXT=`sed -e '1,/^$/ d' < "$2"`

  EMAIL=`echo -n "$TEXT" | grep '^.*@.*' | sed -n 1p | cut -f1 -d' '`
  if [ $EMAIL ]; then
    FROM=`formail -zx From: < $2`
    sms=`cat $2`
    message="From: sms@localhost
To: $EMAIL
Subject: New SMS received from ${FROM}
 
${sms}"

 
    echo -n "$message" | /usr/sbin/sendmail "$EMAIL"
  fi
 
'bash' Syntax Highlight powered by GeSHi


Member
Registered:
Nov 2010
Location: Sindh, Pakistan
Topic owner
Thanks Keke

I want to forward incoming SMS to my group as well as email to group address


« Last edit by mfaisal on Wed Dec 29, 2010 11:25, 169 months ago. »
Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
mfaisal wrote
I want to forward incoming SMS to my group as well as email to group address

Just combine your two scripts... ;)

You can also write different files for different jobs, but there must still be only one eventhandler for smsd. For example eventhandler = /usr/local/bin/smsd_eventhandler.sh. This script could be like:

#!/bin/bash

.  /usr/local/bin/smsd_eventhandler_sms_group.sh
.  /usr/local/bin/smsd_eventhandler_sms_email.sh
 
'bash' Syntax Highlight powered by GeSHi


In that case two files are included into the eventhandler script. Files will see variables and functions (and program flow) which are defined before the file is included. It is also possible to call external scripts, in this case scripts are executed and do not see what is in the main eventhandler:

#!/bin/bash

/usr/local/bin/smsd_eventhandler_sms_group.sh "$1" "$2" "$3"
/usr/local/bin/smsd_eventhandler_sms_email.sh "$1" "$2" "$3"
 
'bash' Syntax Highlight powered by GeSHi


Member
Registered:
Nov 2010
Location: Sindh, Pakistan
Topic owner
Dear Keke,


TEXT=`sed -e '1,/^$/ d' < "$2"`
if echo -n "$TEXT" | grep "ITOPS" >/dev/null; then
# Do the actions...
fi

above mention script grep the ITOPS word from the message and forward to the desiree group, but also i want to email the same message to my email group.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
keke wrote
mfaisal wrote
I want to forward incoming SMS to my group as well as email to group address

Just combine your two scripts... ;)

It seems that you do not want to write your own scripts... ;)

Here is the combined script, but it's the last one I write for you. You could read the manual Advanced Bash-Scripting Guide ... ;)

#!/bin/bash

KEYWORD="ITOPS"

EMAIL_GROUP="
sysadmin@mblonline.com
other_address@somedomain.com
"


SMS_GROUP="
358401111111
358402222222
358403333333
"


MAIL="/usr/sbin/sendmail"
EMAIL_FROM="sms@mblonline.com"
SUBJECT="New SMS received from FROM"

if [ "$1" = "RECEIVED" ]; then

  TEXT=`sed -e '1,/^$/ d' < "$2"`
  if echo -n "$TEXT" | grep "$KEYWORD" >/dev/null; then

    for recipient in $SMS_GROUP
    do
      TMPFILE=`mktemp /tmp/smsd_XXXXXX`
      echo "To: $recipient" >> $TMPFILE
      echo "" >> $TMPFILE
      echo -n "$TEXT" >> $TMPFILE
 
      FILE=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
      mv $TMPFILE $FILE
    done

    FROM=`formail -zx From: < $2`
    SUBJECT=${SUBJECT//FROM/$FROM}
    sms=`cat $2`
    message="From: $EMAIL_FROM
Subject: $SUBJECT
 
${sms}"


    for recipient in $EMAIL_GROUP
    do
      echo -n "$message" | $MAIL $recipient
    done

  fi
fi
 
 
'bash' Syntax Highlight powered by GeSHi


Please note that I have not tested that quickly written sample script. It may contain typos, or anything. If it's functionality is not good for your purposes, feel free to change it... ;)

Member
Registered:
Nov 2010
Location: Sindh, Pakistan
Topic owner
Dear Keke,

I am very gratefull to you. I need one more favour:

send the sms to SENDER like:

Thanks for SMS, we will contact you soon.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
See this: [answered] auto responder + sms2email - post #3.

  This topic is locked

Page:  1

SMSTools3 Community » Help and support Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.