-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldm_checker
executable file
·42 lines (42 loc) · 1.48 KB
/
ldm_checker
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
#!/bin/sh
set -eu
exit_code=0
# shellcheck disable=SC2013
for meta in $(awk '!/^#/ {print $3","$4}' ldm.conf); do
timeout="$(( ${meta%%,*} + 60 ))"
conffile="${meta##*,}"
if ! pgrep -f "unified_client .* ${meta%%,*} ${conffile}" > /dev/null 2>&1; then
printf "No unified_client running for configured %s\n" "${meta}"
exit_code=1
fi
ssid=$(sed -n -e 's/^[[:space:]]*//g' -e 's/"//g' -e '/ssid/s/ssid=//p' "config/${conffile}" | head -n1)
if [ -f "/run/rfctf_status/${ssid}_attempt" ]; then
attempt_mtime=$(stat -c %Y "/run/rfctf_status/${ssid}_attempt")
currtime=$(date +%s)
diff=$(( currtime - attempt_mtime ))
if [ "${diff}" -gt "${timeout}" ]; then
printf "No connection attempt on configured ssid %s in %ss\n" "${ssid}" "${diff}"
exit_code=1
fi
unset attempt_mtime diff
if [ "${1:-}" != "--test" ]; then
if [ -f "/run/rfctf_status/${ssid}_active" ]; then
active_mtime=$(stat -c %Y "/run/rfctf_status/${ssid}_active")
currtime=$(date +%s)
diff=$(( currtime - active_mtime ))
if [ "${diff}" -gt "${timeout}" ]; then
printf "No connection success on configured ssid %s in %ss\n" "${ssid}" "${diff}"
exit_code=1
fi
unset active_mtime diff
else
printf "No connection success on configured ssid %s\n" "${ssid}"
exit_code=1
fi
fi
else
printf "No connection attempt on configured ssid %s\n" "${ssid}"
exit_code=1
fi
done
exit "${exit_code}"