-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendsms
106 lines (86 loc) · 2.08 KB
/
sendsms
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# This script send a text sms at the command line by creating
# a sms file in the outgoing queue.
# $1 is the destination phone number.
# $2 is the message text.
# If you leave $2 or both empty, the script will ask you.
# If you give more than 2 arguments, last is taken as a text and
# all other are taken as destination numbers.
# If a destination is asked, you can type multiple numbers
# delimited with spaces.
# Keys for example: "password" and "keke":
# KEYS="5f4dcc3b5aa765d61d8327deb882cf99 4a5ea11b030ec1cfbc8b9947fdf2c872"
KEYS=""
# When creating keys, remember to use -n for echo:
# echo -n "key" | md5sum
USER="smsd"
GROUP="smsd"
# Will need echo which accepts -n argument:
ECHO=echo
if! [ -z "$KEYS" ]; then
printf "Key: "
read KEY
if [ -z "$KEY" ]; then
echo "Key required, stopping."
exit 1
fi
KEY=`$ECHO -n "$KEY" | md5sum | awk '{print $1;}'`
if! echo "$KEYS" | grep "$KEY" >/dev/null; then
echo "Incorrect key, stopping."
exit 1
fi
fi
DEST=$1
TEXT=$2
if [ -z "$DEST" ]; then
printf "Destination(s): "
read DEST
if [ -z "$DEST" ]; then
echo "No destination, stopping."
exit 1
fi
fi
if [ -z "$TEXT" ]; then
printf "Text: "
read TEXT
if [ -z "$TEXT" ]; then
echo "No text, stopping."
exit 1
fi
fi
if [ $# -gt 2 ]; then
n=$#
while [ $n -gt 1 ]; do
destinations="$destinations $1"
shift
n=`expr $n — 1`
done
TEXT=$1
else
destinations=$DEST
fi
echo "-- "
echo "Text: $TEXT"
ALPHABET=""
if which iconv > /dev/null 2>&1; then
if! $ECHO -n "$TEXT" | iconv -t ISO-8859-15 >/dev/null 2>&1; then
ALPHABET="Alphabet: UCS"
fi
fi
for destination in $destinations
do
echo "To: $destination"
TMPFILE=`mktemp /tmp/smsd_XXXXXX`
$ECHO "To: $destination" >> $TMPFILE
[ -n "$ALPHABET" ] && $ECHO "$ALPHABET" >> $TMPFILE
$ECHO "" >> $TMPFILE
if [ -z "$ALPHABET" ]; then
$ECHO -n "$TEXT" >> $TMPFILE
else
$ECHO -n "$TEXT" | iconv -t UNICODEBIG >> $TMPFILE
fi
chown $USER:$GROUP $TMPFILE
chmod 0660 $TMPFILE
FILE=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $TMPFILE $FILE
done