-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsafe-parser-cdr-radius-http.sh
More file actions
executable file
·52 lines (40 loc) · 1.1 KB
/
safe-parser-cdr-radius-http.sh
File metadata and controls
executable file
·52 lines (40 loc) · 1.1 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
#!/bin/sh
# line for run like a daemon
# RADACCT_DIR='/var/log/radacct/temp/' STORAGE_DIR='/var/log/radacct/detail/' /usr/sbin/daemon -P /var/run/parser-cdr-radius-http.run -r -f /usr/local/bin/safe-parser-cdr-radius-http.sh
# bins
DIRNAME="$(/usr/bin/which dirname)"
DIRNAME="${DIRNAME:-/usr/bin/dirname}"
PGREP="$(/usr/bin/which pgrep)"
PGREP="${PGREP:-/bin/pgrep}"
PKILL="$(/usr/bin/which pkill)"
PKILL="${PKILL:-/bin/pkill}"
SLEEP="$(/usr/bin/which sleep)"
SLEEP="${SLEEP:-/bin/sleep}"
# global variables
BASEDIR="$(${DIRNAME} $0)"
SCRIPTNAME="parser-cdr-radius-http.sh"
NULL='/dev/null'
SLEEP_MON=1
"${BASEDIR}"/"${SCRIPTNAME}" -h > "${NULL}" || exit 1
_run_parser() {
"${BASEDIR}"/"${SCRIPTNAME}" &
}
_monitor() {
while true; do
${SLEEP} ${SLEEP_MON}
if ${PGREP} -fq "${SCRIPTNAME}"; then
continue
fi
_run_parser
done
}
# Don't die if stdout/stderr can't be written to
trap '' PIPE
if ${PGREP} -fq "${SCRIPTNAME}" && ${PGREP} -fq "safe-${SCRIPTNAME}"; then
exit 0
fi
if ${PGREP} -fq "safe-${SCRIPTNAME}"; then
${PKILL} -f "safe-${SCRIPTNAME}" || exit 1
fi
_monitor
exit $?