2018-01-28 17:28:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
# (1) Primary init.
|
|
|
|
#--------------------------------------------------------#
|
|
|
|
# (1) Get absolute folder #
|
|
|
|
ROOT=$(dirname `realpath $0`);
|
|
|
|
ROOT=`dirname $ROOT`;
|
|
|
|
|
|
|
|
# (2) Check lock file #
|
|
|
|
test ! -f $ROOT/.lock && echo "Daemon not started" && exit 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# (2) While viewing loop
|
|
|
|
#--------------------------------------------------------#
|
|
|
|
# (1) Initialise vars #
|
|
|
|
declare -A SERV;
|
|
|
|
|
|
|
|
# (3) For each service update #
|
|
|
|
while sleep 1; clear; do
|
|
|
|
|
|
|
|
# (4) Get last value from lines beginning by 'GSTA' #
|
|
|
|
SERV_LIST="`cat $BUF_IN | grep -Po "^SYSD(.+)$" | sed 's/^SYSD\(.\+\)$/\1/g' | tail -n20`";
|
|
|
|
|
|
|
|
# (5) Store each service #
|
|
|
|
while IFS= read -r line; do
|
|
|
|
|
2018-01-28 18:16:30 +00:00
|
|
|
test "`echo -ne $line | wc -m`" -ge 5 && SERV["${line:1}"]="${line:0:1}";
|
2018-01-28 17:28:59 +00:00
|
|
|
|
|
|
|
done <<< "$SERV_LIST";
|
|
|
|
|
|
|
|
# (6) Display each service #
|
|
|
|
for s in "${!SERV[@]}"; do
|
|
|
|
|
2018-01-28 18:16:30 +00:00
|
|
|
# if failed -> red
|
|
|
|
if [ "${SERV[$s]}" = "0" ]; then
|
|
|
|
echo -e "(${SERV[$s]}) \e[31m$s\e[0m";
|
|
|
|
|
|
|
|
# if activating -> orange
|
|
|
|
elif [ "${SERV[$s]}" = "2" ]; then
|
|
|
|
echo -e "(${SERV[$s]}) \e[33m$s\e[0m";
|
|
|
|
|
2018-01-28 17:28:59 +00:00
|
|
|
# if active -> green
|
2018-01-28 18:16:30 +00:00
|
|
|
elif [ "${SERV[$s]}" = "3" ]; then
|
|
|
|
echo -e "(${SERV[$s]}) \e[32m$s\e[0m";
|
|
|
|
|
|
|
|
# if inactive -> grey
|
|
|
|
else
|
|
|
|
echo -e "(${SERV[$s]}) \e[90m$s\e[0m";
|
|
|
|
|
|
|
|
fi;
|
2018-01-28 17:28:59 +00:00
|
|
|
|
|
|
|
done;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
done;
|