-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.sh
More file actions
executable file
·234 lines (185 loc) · 5.8 KB
/
Copy pathimport.sh
File metadata and controls
executable file
·234 lines (185 loc) · 5.8 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
############################################################
# This script will automate the process of #
# Logging Calls on a Pi-Star Hotpot #
# to assist with Net Logging #
# #
# VE3RD Created 2021/07/05 #
############################################################
set -o errexit
set -o pipefail
set -e
set -o errtrace
set -E -o functrace
ver=2021123001
RED="\e[31m"
GREEN="\e[32m"
LTMAG="\e[95m"
LTGREEN="\e[92m"
LTCYAN="\e[96m"
YELLOW="\e[33m"
ENDCOLOR="\e[0m"
f1=/home/pi-star/PiMon/ysf.csv
f2=/usr/local/etc/stripped.csv
f3=/usr/local/etc/stripped2.csv
sudo mount -o remount,rw /
#printf '\e[9;1t'
callstat=""
callinfo="No Info"
lastcall2=""
lastcall1=""
netcont="none"
TG=""
dur=$((0))
lfdts=""
dts=""
line1=""
nline1=""
calli=""
src="RF" #"NET"
active=0
sline=" "
oldline=""
newline=""
server=""
call=""
line2=""
yat=""
err_report()
{
echo "Error on line $1"
echo "Last Call = $call"
echo "Last TCall = $tcall"
./pimon.sh ReStart
}
trap 'err_report $LINENO' ERR
fnEXIT() {
echo -en "${BOLD}${WHI}THANK YOU FOR USING pimon by VE3RD!${SGR0}${DEF}"
echo ""
exit
}
trap fnEXIT SIGINT SIGTERM
#M: 2021-12-29 14:55:46.923 YSF, received network data from WB2FLX to DG-ID 0 at FCS00390
function updatefromqrz(){
. /home/pi-star/.qrz.conf
# get a session key from qrz.com
session_xml=$(curl -s -X GET 'http://xmldata.qrz.com/xml/current/?username='${user}';password='${password}';agent=qrz_sh')
# check for login errors
#e=$(printf %s "$session_xml" | grep -oP "(?<=<Error>).*?(?=</Error>)" ) # only works with GNU grep
e=$(printf %s "$session_xml" | awk -v FS="(<Error>|<\/Error>)" '{print $2}' 2>/dev/null | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n//g')
if [ "$e" != "" ]
then
echo "The following error has occured: $e"
###exit
fi
# extract session key from response
session_key=$(printf %s "$session_xml" |grep -oP '(?<=<Key>).*?(?=</Key>)') # only works with GNU grep
#session_key=$(printf %s "$session_xml" | awk -v FS="(<Key>|<\/Key>)" '{print $2}' 2>/dev/null | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n//g')
# lookup callsign at qrz.com
lookup_result=$(curl -s -X GET 'http://xmldata.qrz.com/xml/current/?s='${session_key}';callsign='${call}'')
ncall="OK"
# check for login errors
#e=$(printf %s "$lookup_result" | grep -oP "(?<=<Error>).*?(?=</Error>)" ) # only works with GNU grep
e=$(printf %s "$lookup_result" | awk -v FS="(<Error>|<\/Error>)" '{print $2}' 2>/dev/null | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n//g')
if [ "$e" != "" ]
then
echo "$call - Not Found at QRZ"
cnt=$((cnt+1))
nocall="$cnt,$call,NoName,NA,NA.NA,NA,NA"
echo "$nocall" >> /usr/local/etc/stripped2.csv
ncall="NO"
# exit
# fi
else
# grep field values from xml and put them into variables
#for f in "call" "fname" "name" "addr1" "addr2" "country" "grid" "email" "user" "lotw" "mqsl" "eqsl" "qslmgr"
for f in "call" "fname" "name" "addr1" "addr2" "state" "country"
do
# z=$(printf %s "$lookup_result" | grep -oP "(?<=<${f}>).*?(?=</${f}>)" ) # only works with GNU grep
z=$(printf %s "$lookup_result" | awk -v FS="(<${f}>|<\/${f}>)" '{print $2}' 2>/dev/null | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n//g')
# eval "$f='${z}'"
# eval "$f=${z}"
done
touch /usr/local/etc/stripped2.csv
cnt=$((cnt+1))
newcall=$(echo "$cnt","$call","$fname","$name","$addr2","$state","$country")
echo -e "${LTMAG}QRZ: $newcall $cnt added to stripped2.csv ${ENDCOLOR}"
echo "$newcall" >> /usr/local/etc/stripped2.csv
fi
}
function checkcall(){
# s1checka=$( grep "$call", /usr/local/etc/stripped.csv | head -1 )
# echo "$s1checka"
if grep -F ,"$call", /usr/local/etc/stripped.csv
then
echo -en "${LTGREEN}$Time Call:$call Found in Stripped.csv ${ENDCOLOR} \n"
else
if grep -F ,"$call", /usr/local/etc/stripped2.csv
then
echo -en "${LTCYAN} $Time Call $call Found in Stripped2.csv ${ENDCOLOR} \n"
else
echo "$Time Using QRZ to Locate $call"
updatefromqrz
sleep 5
fi
fi
}
function GeNextLine(){
line1=$(tail -n 1 "$f1" | sed 's/ */ /g')
newline="$line1"
# substr="transmission"
substr="data"
if [ "$oldline" != "$newline" ] && [[ "$line1" == *"$substr"* ]]; then
call=$(echo "$line1" | sed 's/ */ /g' | grep -o 'from.*' | tr "-" " " | tr "/" " " | cut -d " " -f2 )
clen=$(echo $call | wc -c)
echo "Call = |$call| - $clen"
if [ "$clen" -gt 3 ] && [ "$clen" -le 7 ]; then
checkcall
fi
oldline="$newline"
fi
}
function StartUp()
{
# f1=$(ls -tv /var/log/pi-star/MMDVM* | tail -n 1 )
# line1=$(tail -n 1 "$f1" | sed 's/ */ /g')
lcntt=$(tail -n1 /usr/local/etc/stripped2.csv | cut -d "," -f1)
cnt=$((lcntt))
echo "Records Found in stripped2.csv = $cnt"
}
######## Start of Main Program
callstat=""
######### Main Loop Starts Here
#echo "Starting Loop"
StartUp
#while IFS="" read -r p || [ -n "$p" ]
while IFS="" read -r p
do
call1=$(echo "$p" | cut -d "," -f 2)
echo " Raw Call = $call1"
call=$(echo "$call1" | tr "-" " " | tr "/" " " | cut -d " " -f1 )
echo "Stripped Call = $call"
if [ ! -z "$call" ]; then
mt=$(sudo sed -n '/'",$call",'/p' /usr/local/etc/stripped.csv | head -1) > /dev/null
if [ -z "$mt" ]; then
echo "$call - Not Found in stripped.csv"
mt=$(sudo sed -n '/',"$call",'/p' /usr/local/etc/stripped2.csv | head -1) > /dev/null
if [ -z "$mt" ]; then
echo "$call -- Not Found in stripped2.csv"
updatefromqrz
else
echo "$call -- Found in stripped2.csv"
fi
else
echo "$call - Found in stripped.csv"
fi
fi
done < /home/pi-star/PiMon/ysf.csv
#while true
#do
# cm=0
# Time=$(date '+%T')
# GetLasLine
# sync
# sleep 5.0
#done