Author |
Post |
|
#1 Mon Dec 27, 2010 07:06, 169 months ago.
|
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.
|
|
#2 Mon Dec 27, 2010 11:25, 169 months ago.
|
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.
|
|
#3 Tue Dec 28, 2010 06:57, 169 months ago.
|
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.
|
|
#4 Tue Dec 28, 2010 10:59, 169 months ago.
|
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
|
|
#5 Wed Dec 29, 2010 09:37, 169 months ago.
|
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
|
|
#6 Wed Dec 29, 2010 11:05, 169 months ago.
|
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
|
|
#7 Wed Dec 29, 2010 11:24, 169 months ago.
|
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. »
|
|
#8 Wed Dec 29, 2010 13:24, 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
|
|
#9 Thu Dec 30, 2010 04:53, 169 months ago.
|
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.
|
|
#10 Thu Dec 30, 2010 12:04, 169 months ago.
|
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...
|
|
#11 Thu Jan 13, 2011 11:40, 169 months ago.
|
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.
|
|
#12 Thu Jan 13, 2011 11:52, 169 months ago.
|
Administrator
Registered: May 2009
Location: Jyväskylä, Finland
|
|