-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsss-client
61 lines (51 loc) · 1.62 KB
/
sss-client
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
function usage() {
if [ -n "$1" ]; then echo $1; fi
echo "Usage: sss-client [-d callerid] [-u accountsid] [-p authtoken] "
exit 1
}
read -p "Enter Message (Max 160 Chars.): " MSG
read -p "Enter Number (918879886525) : " PHONE
VERBOSE=0
while getopts ":u:p:d:v" opt; do
case "$opt" in
d) CALLERID_ARG=$OPTARG ;;
u) ACCOUNTSID_ARG=$OPTARG ;;
p) AUTHTOKEN_ARG=$OPTARG ;;
v) VERBOSE=1 ;;
*)
echo "Unknown param: $opt"
usage
;;
esac
done
CONFIGFILE=".config"
# test configfile
if [ -n "$CONFIGFILE" -a ! -f "$CONFIGFILE" ]; then
echo "Configfile not found: $CONFIGFILE"
usage
fi
# source configfile if given
if [ -n "$CONFIGFILE" ]; then
. "$CONFIGFILE"
# source the default ~/.twiliorc if it exists
elif [ -f ~/.twiliorc ]; then
. ~/.twiliorc
fi
# verify params
if [ -z "$ACCOUNTSID" ]; then usage "AccountSid not set"; fi
if [ -z "$AUTHTOKEN" ]; then usage "AuthToken not set"; fi
if [ -z "$CALLERID" ]; then usage "CallerID not set"; fi
# Get message from stdin, taking only first 160 chars
MSG=${MSG:0:160}
# Verify MSG
if [ -z "$MSG" ]; then usage "No content for the SMS was read from STDIN."; fi
echo -n "Sending SMS to $PHONE from $CALLERID..."
# initiate a curl request to the Twilio REST API, to begin a phone call to that number
RESPONSE=$(curl -fSs -u "$ACCOUNTSID:$AUTHTOKEN" -d "From=$CALLERID" -d "To=$PHONE" -d "Body=$MSG" "https://api.twilio.com/2010-04-01/Accounts/$ACCOUNTSID/SMS/Messages" 2>&1)
if [ $? -gt 0 ]; then
echo "Failed to send SMS to $PHONE: $RESPONSE"
else
echo "done"
fi
if [ "$VERBOSE" -eq 1 ]; then echo $RESPONSE; fi