SMS Server Tools 3
This site is hosted by Kekekasvi.com
 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. Please login or register. Sun Mar 07, 2021 18:57
SMSTools3 Community » Help and support Bottom

[answered] Help in Script

  This topic is locked

Page:  1

Author Post
Member
Registered:
Nov 2010
Location: Sindh, Pakistan
Operating system name and version: SUSE 10
Version of smsd: 3.1.14
Smsd installed from: sources
Name and model of a modem / phone: Moxa U110
Interface: USB


I made a following script to execute my operation related script if someone send a sms with contain word "fw", now i want to deploy some security means like if SMS received to specific numbers like "03452057192 03452409990 03432120500" then execute the script otherwise if number not matched than send a SMS with "You are not authrized to perform this action"

########################################
#!/bin/bash

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


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

if echo -n "$TEXT" | grep -i "FW" >/dev/null; then
/scripts/fw
else
exit
fi

fi
######################################

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
See this post for examples.

Member
Registered:
Nov 2010
Location: Sindh, Pakistan
Topic owner
But how can i configure a reply msg that "You are not authorized to perform this action" to the number that not matched a list.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
mfaisal wrote
But how can i configure a reply msg that "You are not authorized to perform this action" to the number that not matched a list.

As you already have a send_sms() function, just use it like this:

  if [[ $ALLOWED_NUMBERS == *$key* ]]; then

    # Do the actions...

  else

    send_sms "$FROM" "You are not authorized to perform this action"

  fi
 
'bash' Syntax Highlight powered by GeSHi


If you have lost your copy of sendsms() function, you can get it from here.

Member
Registered:
Nov 2010
Location: Sindh, Pakistan
Topic owner
Hello KEKE,

As per my understanding or experience in Shell programming, i made a following script, I am requesting you yo please correct my script

*****************************************************

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

ALLOWED_NUMBERS="923212911016 923468200033"

FROM=`formail -zx From: < $2`
key=" $FROM "

if [[ $ALLOWED_NUMBERS == *$key* ]]; then

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

if echo -n "$TEXT" | grep -i "FW" > /dev/null; then
/scripts/test
else

send_sms()
{

FILE=`mktemp /tmp/send_XXXXXX`
echo "To: $1" >> $FILE
if [ "x$2" != "x" ]; then
echo "Provider: $2" >> $FILE

fi
echo "You are not Authorized to perform an action" >> $FILE
echo "" >> $FILE
echo -n "$2" >> $FILE
FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $FILE $FILE2

}

exit

fi

fi

fi

**************************************************

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

As per my understanding or experience in Shell programming, i made a following script, I am requesting you please correct my script, i m very gratefull to you. Kindly consider this one.

**************************************************

#!/bin/bash
#Script Created by FAISAL (m.faisal@meezanbank.com)

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

ALLOWED_NUMBERS="923212911016"

FROM=`formail -zx From: < $2`
key=" $FROM "

if [[ $ALLOWED_NUMBERS == *$key* ]]; then

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

if echo -n "$TEXT" | grep -i "FW" > /dev/null
then
/scripts/test

if test $? = 0
then
FILE=`mktemp /tmp/send_XXXXXX`
echo "To: $FROM" >> $FILE
echo "Your Requested Operation is in Progress" >> $FILE
echo "" >> $FILE
FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $FILE $FILE2
else
FILE=`mktemp /tmp/send_XXXXXX`
echo "To: $FROM" >> $FILE
echo "Your Requested Operation is failed!" >> $FILE
echo "" >> $FILE
FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $FILE $FILE2

else
FILE=`mktemp /tmp/send_XXXXXX`
echo "To: $1" >> $FILE
echo "You are not Authorized to perform an action" >> $FILE
echo "" >> $FILE
FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $FILE $FILE2

exit

**************************************************

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
You already had a working script which was using semd_sms function, see this post once again. Especially notice how send_sms function is placed in the file. Then, call it as shown in the post #4.

When copying code from this post, you have removed the comment line which said: "# List must start and end with space:". Now, when your list of numbers does not start and end with space, your script will not work. Please keep that comment line in the code, and include those spaces in the list.

For more details on scripting, please visit this site: Advanced Bash-Scripting Guide.

Member
Registered:
Nov 2010
Location: Sindh, Pakistan
Topic owner
Dear Please correct my script, i dont understand where i made a mistake.

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

Now my script is:

##############################################

#!/bin/bash
#Script Created by FAISAL (m.faisal@meezanbank.com)

ALLOWED_NUMBERS=" 923212911018 923002878358 "

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

FROM=`formail -zx From: < $2`
key=" $FROM "
if [[ $ALLOWED_NUMBERS == *$key* ]]; then

TEXT=`sed -e '1,/^$/ d' < "$3"`
if echo -n "$TEXT" | grep -i "FW" > /dev/null
then
/scripts/test
else

send_sms()
{
FILE=`mktemp /tmp/send_XXXXXX`
echo "To: $2" >> $FILE
echo "" >> $FILE
echo "You are not Authorized to perform an action" >> $FILE
FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $FILE $FILE2

}

fi

fi

fi

##############################################

If i send a sms from 923212911018 that contain a word like "Fw", then logs says:

GSM1: Exec: eventhandler encountered errors:
GSM1: ! /usr/local/bin/smsd_eventhandler-script1.sh: line 12: : No such file or directory

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

Now my script is:

##############################################

#!/bin/bash
ALLOWED_NUMBERS=" 923212911018 923002878358 "

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

FROM=`formail -zx From: < $2`
key=" $FROM "
if [[ $ALLOWED_NUMBERS == *$key* ]]; then

TEXT=`sed -e '1,/^$/ d' < "$3"`
if echo -n "$TEXT" | grep -i "FW" > /dev/null
then
/scripts/test
else

send_sms()
{
FILE=`mktemp /tmp/send_XXXXXX`
echo "To: $2" >> $FILE
echo "" >> $FILE
echo "You are not Authorized to perform an action" >> $FILE
FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $FILE $FILE2

}

fi

fi

fi

##############################################

If i send a sms from 923212911018 that contain a word like "Fw", then logs says:

GSM1: Exec: eventhandler encountered errors:
GSM1: ! /usr/local/bin/smsd_eventhandler-script1.sh: line 12: : No such file or directory


Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
mfaisal wrote
GSM1: ! /usr/local/bin/smsd_eventhandler-script1.sh: line 12: : No such file or directory

Bash shell is trying to tell that there is a problem in line 12. Check that line. Compare it to the similar line you have in post #1 in this topic. Find the difference and fix it. Line in post #1 is correct.

For the rest of script, I have to repeat:

keke wrote
You already had a working script which was using semd_sms function, see this post once again. Especially notice how send_sms function is placed in the file. Then, call it as shown in the post #4.


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

Now script is working if number is matched with "ALLOWED_NUMBERS" but if number is not matched with "ALLOWED_NUMBERS" then does not generate a sms to sendder, as per my understanding my script is as follow, but i can't understand how can integarate a send_sms function in my script, please, please help me.

#/bin/bash

##########################
ALLOWED_NUMBERS=" 923002878358 "
##########################

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

FROM=`formail -zx From: < $2`
key=" $FROM "

if [[ $ALLOWED_NUMBERS == *$key* ]]; then

TEXT=`sed -e '1,/^$/ d' < "$2"`
if echo -n "$TEXT" | grep -i "FW" > /dev/null
then
/scripts/test
else
send_sms()
{

FILE=`mktemp /tmp/send_XXXXXX`
echo "To: $FROM" >> $FILE
echo "Comment: MBL auto-answer" >> $FILE
FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $FILE $FILE2
send_sms "$FROM" "This Number only accept SMS"

}

fi

fi

fi

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

Now i acheived my target from the following script:

#############################################
ALLOWED_NUMBERS=" 07895245312 "
#############################################

send_sms()
{
FILE=`mktemp /tmp/send_XXXXXX`
echo "To: $FROM" > $FILE
echo "" >> $FILE
echo -n "$2" >> $FILE
FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $FILE $FILE2

}

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

FROM=`formail -zx From: < $2`
key=" $FROM "

if [[ $ALLOWED_NUMBERS == *$key* ]]; then

TEXT=`sed -e '1,/^$/ d' < "$2"`
if echo -n "$TEXT" | grep -i "daily" > /dev/null
then
/scripts/test
else
exit
fi
else
send_sms "$FROM" "You are not authorized to perform this action"

fi
fi

  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.