ioemu/sub-view/systemd

58 lines
1.2 KiB
Bash
Executable File

#!/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
test "`echo -ne $line | wc -m`" -ge 5 && SERV["${line:1}"]="${line:0:1}";
done <<< "$SERV_LIST";
# (6) Display each service #
for s in "${!SERV[@]}"; do
# 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";
# if active -> green
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;
done;
done;