-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.sh
executable file
·56 lines (48 loc) · 910 Bytes
/
send.sh
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
#!/bin/sh
# Modem device
DEV=/dev/ttyACM0
LOCK_FILE=/tmp/sms-lock
#AT&F&C1&D2
if [ -f $LOCK_FILE ]; then
LOCK_PID="$(cat $LOCK_FILE)"
while [ -d /proc/$LOCK_PID ]; do
echo "Lock detected! Waiting ..."
sleep 1
done
fi
echo $$ > $LOCK_FILE
function get_sms_status() {
while true; do
if read -t 10 line; then
if $(echo "$line" | grep -q '^+CMS ERROR'); then
echo "fail"
return 1
fi
if $(echo "$line" | grep -q '^+CMGS: [0-9]\+'); then
echo "success"
return 0
fi
else
echo "timeout"
return 2
fi
done < $DEV
}
get_sms_status &
pid=$!
PHONE="$1"
TEXT="$2"
# we need to put sleep 1 to slow down commands for modem to process
echo -e "ATZ\r" > $DEV
sleep 1
echo -e "AT+CMGF=1\r" > $DEV
sleep 1
echo -e "AT+CMGS=\"$PHONE\"\r" > $DEV
sleep 1
echo -e "$TEXT\x1A\r" > $DEV
echo "PID: $pid"
wait $pid
status="$?"
rm -f $LOCK_FILE
echo "status: $status"
exit $status