50 lines
1.1 KiB
Bash
Executable File
50 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
export LANG='en_US.UTF-8'
|
|
# set column width
|
|
COLUMNS=2
|
|
# colors
|
|
green="\e[1;32m"
|
|
red="\e[1;31m"
|
|
undim="\e[0m"
|
|
declare -A services
|
|
services["docker"]="Docker"
|
|
services["smartd"]="Smart"
|
|
services["smbd"]="Samba"
|
|
services["nmbd"]="NetBIOS"
|
|
services["wsdd"]="WSD"
|
|
services["isc-dhcp-relay"]="DHCP Relay"
|
|
|
|
|
|
# Sorting associated array
|
|
names=$(
|
|
for name in ${!services[@]}; do
|
|
echo "${services[$name]}:::$name"
|
|
done | sort | awk -F::: '{print $2}'
|
|
)
|
|
|
|
k=0
|
|
out=""
|
|
for name in $names; do
|
|
VAL=${services[$name]}
|
|
((k++))
|
|
# color green if service is active, else red
|
|
service_status=($(systemctl is-active "$name"))
|
|
if [[ "${service_status}" == "active" ]]; then
|
|
_tmp=$(printf "%-13s %-16s," "${services[$name]}:" "${green}${undim}")
|
|
out+="${_tmp},"
|
|
else
|
|
_tmp=$(printf "%-13s %-16s," "${services[$name]}:" "${red}${undim}")
|
|
out+="${_tmp},"
|
|
fi
|
|
# insert \n every $COLUMNS column
|
|
if [ $((($k) % $COLUMNS)) -eq 0 ]; then
|
|
out+="\n"
|
|
fi
|
|
done
|
|
|
|
out+="\n"
|
|
|
|
printf "\nServices:\n"
|
|
printf "$out" | column -ts $',' | sed -e 's/^/ /'
|