-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathreadSMS.sh
76 lines (63 loc) · 7.07 KB
/
readSMS.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Run this file as root@Openwrt:# bash readSMS.sh
# Authored by - Pratik Farkase
echo -e "Checking SIM CARD Status, "
comgt > sim.txt
if grep -w -q "ERROR" sim.txt; then
echo -e "\n"
echo -e "SIM not Inserted, Unable to read SMS, Please Enter SIM\n"
fi
if grep -w -q "Registered" sim.txt; then
echo -e "SIM CARD DETECTED,\n"
echo -e "AT+CPMS? \r\n" > /dev/ttyUSB2 && timeout 2 cat /dev/ttyUSB2 > numbermsgs.txt
echo -e "AT+CMGF=1 \r\n" > /dev/ttyUSB2
sleep 1
#echo -e "AT+CPMS? \r\n" > /dev/ttyUSB2 && timeout 2 cat /dev/ttyUSB2 > numbermsgs.txt
echo $(grep -Eo '[0-9\.]+' numbermsgs.txt) > no.txt
var=$(awk '{ print $1 }' no.txt)
echo -e "Total Number of received messages = $var"
echo -e "AT+CMGL=\"ALL\" \r\n" > /dev/ttyUSB2 && timeout 2 cat /dev/ttyUSB2 > SMS.txt
sed -n '/+CMGL:/,/"/p' SMS.txt | awk '{gsub("+CMGL:", "");print}' SMS.txt > filter.txt
grep -o '".*"' filter.txt | sed 's/"//g' > comma.txt && sed -i '/ALL/d' comma.txt
j=0
for (( k=0; k<$var; k++ ))
do
filecontent=$(cat comma.txt)
IFS=',' read -r -a array <<< "$filecontent"
i=0
for element in "${array[i]}"
do
echo -e "Message : $j"
echo -e "Status = "$element""
i=1
for element in "${array[i]}"
do
echo -e "Number = "$element""
i=3
for element in "${array[i]}"
do
echo -e "Date = "$element" (YYYY/MM/DD)"
i=4
for element in "${array[i]}"
do
echo -e "Time = "$element""
done
done
done
done
echo -e "AT+CMGR=$j \r\n" > /dev/ttyUSB2 && timeout 2 cat /dev/ttyUSB2 > text.txt
echo -e "Message = $(sed -n '/+CMGR:/,/OK/{/+CMGR:/b;/OK/b;p}' text.txt)"
j=$((j+1))
echo -e "\n"
echo "$(tail -n +2 comma.txt)" > comma.txt
done
grep -o '".*"' filter.txt | sed 's/"//g' > comma.txt && sed -i '/ALL/d' comma.txt
#echo -e "AT+CMGL=\"ALL\" \r\n" > /dev/ttyUSB2 && timeout 2 cat /dev/ttyUSB2 > SMS.txt
fi
if grep -w -q "ERROR" SMS.txt; then
echo -e "\n"
echo -e "Unable to display messages\n"
else
#cat SMS.txt
echo -e "Done\n"
fi