File: sql_demo

package info (click to toggle)
smstools 3.1.15-1.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 1,656 kB
  • ctags: 879
  • sloc: ansic: 14,857; sh: 1,195; php: 115; makefile: 48; awk: 17
file content (35 lines) | stat: -rwxr-xr-x 882 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh

# Please read the description in the manual of SMS Server Tools.

#run this script only when a message was received.
if [ "$1" != "RECEIVED" ]; then exit; fi;

#Define the database parameters
SQL_HOST=localhost
SQL_USER=root
SQL_PASSWORD=
SQL_DATABASE=smsd
SQL_TABLE=demo

#Extract data from the SMS file
FROM=`formail -zx From: < $2`
TEXT=`formail -I "" <$2 | sed -e"1d"`

#Set some SQL parameters
if [ "$SQL_PASSWORD" != "" ]; then 
  SQL_ARGS="-p $SQL_PASSWORD"; 
else 
  SQL_ARGS=""; 
fi
SQL_ARGS="-h $SQL_HOST -u $SQL_USER $SQL_ARGS -D $SQL_DATABASE -s -e"

#Do the SQL Query
AMOUNT=`mysql $SQL_ARGS "select amount from $SQL_TABLE where msisdn=\"$FROM\" and password=\"$TEXT\" ;"`

#Create an answer SM with the amount
FILENAME=`mktemp /var/spool/sms/outgoing/answerXXXXXX`
echo "To: $FROM" >$FILENAME
echo "" >> $FILENAME
echo "Your amount is $AMOUNT" >>$FILENAME