Author |
Post |
|
#1 Sat Jun 18, 2011 14:46, 163 months ago.
|
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 ######################################
|
|
#2 Sat Jun 18, 2011 15:10, 163 months ago.
|
Administrator
Registered: May 2009
Location: Jyväskylä, Finland
|
See this post for examples.
|
|
#3 Sun Jun 19, 2011 06:38, 163 months ago.
|
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.
|
|
#4 Sun Jun 19, 2011 10:54, 163 months ago.
|
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.
|
|
#5 Mon Jun 20, 2011 05:55, 163 months ago.
|
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
**************************************************
|
|
#6 Mon Jun 20, 2011 10:12, 163 months ago.
|
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
**************************************************
|
|
#7 Mon Jun 20, 2011 10:39, 163 months ago.
|
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.
|
|
#8 Mon Jun 20, 2011 11:31, 163 months ago.
|
Member
Registered: Nov 2010
Location: Sindh, Pakistan
Topic owner
|
Dear Please correct my script, i dont understand where i made a mistake.
|
|
#9 Mon Jun 20, 2011 12:38, 163 months ago.
|
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
|
|
#10 Mon Jun 20, 2011 15:47, 163 months ago.
|
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
|
|
#11 Mon Jun 20, 2011 17:32, 163 months ago.
|
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.
|
|
#12 Tue Jun 21, 2011 05:56, 163 months ago.
|
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
|
|
#13 Tue Jun 21, 2011 07:37, 163 months ago.
|
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
|