-
Notifications
You must be signed in to change notification settings - Fork 1
/
dxlscanner.sh
76 lines (59 loc) · 1.55 KB
/
dxlscanner.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
76
#!/bin/bash
workingdir="$( cd "$(dirname "$0")" ; pwd -P )"
source ${workingdir}/ws-options.conf
piddir=${workingdir}/pidfiles
bindir=${workingdir}/bin
SCANNER=${bindir}/scanner
command -v ${SCANNER} >/dev/null 2>&1 || { echo "I miss " ${SCANNER} >&2; exit 1; }
function startscanner {
echo "Starte scanner $i"
${SCANNER} -p ${scan_sdrtst} -u ${scan_sondeudp} -f ${sf} -s 1500 -v -o ${SDRCFG} -b ${workingdir}/${file_blacklist} -w ${workingdir}/${file_whitelist} -q 50 -n ${level} &
scanner_pid=$!
echo $scanner_pid > $PIDFILE
sleep 2
}
function sanitycheck {
# check pidfiles in piddir
shopt -s nullglob # no error if no PIDFILE
for f in ${piddir}/*.pid; do
pid=`cat $f`
if [ -f /proc/$pid/exe ]; then ## pid is running?
echo "$(basename $f) ok pid: $pid"
else ## pid not running
echo "$(basename $f) died"
rm $f
fi
done
}
function checkproc {
#checks if prog is running or not
if [ -s $PIDFILE ];then ##have PIDFILE
pid=$(cat $PIDFILE)
if [ -f /proc/$pid/exe ]; then ## pid is running?
return 0
else ## pid not running
return 1
fi
else ## no PIDFILE
return 1
fi
}
### kill procs
if [ "x$1" == "xstop" ];then
killall scanner
sanitycheck
exit 0
fi
for i in ${activesdr[@]}; do
eval scan_sdrtst="\${$i[scan_sdrtst]}"
eval scan_sondeudp="\${$i[scan_sondeudp]}"
eval sf="\${$i[sf]}"
eval level="\${$i[level]}"
SDRCFG=${workingdir}/sdrcfg-${i}.txt
PIDFILE=${piddir}/scanner-${i}.pid
checkproc
returnval=$?
if [ $returnval -eq 1 ];then
startscanner
fi
done