rename to repflect correct name 2nd try

This commit is contained in:
Mario Fetka
2024-04-16 12:52:04 +02:00
parent 4be463f9ec
commit c5986ded53
8 changed files with 0 additions and 0 deletions

37
update-motd.d/40-services Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
# set column width
COLUMNS=3
# colors
green="\e[1;32m"
red="\e[1;31m"
undim="\e[0m"
services=("zabbix-server" "zabbix-agent2" "apache2" "mariadb" "fail2ban" "chrony" "sendmail")
# sort services
IFS=$'\n' services=($(sort <<<"${services[*]}"))
unset IFS
service_status=()
# get status of all services
for service in "${services[@]}"; do
service_status+=($(systemctl is-active "$service"))
done
out=""
for i in ${!services[@]}; do
# color green if service is active, else red
if [[ "${service_status[$i]}" == "active" ]]; then
out+="${services[$i]}:,${green}${service_status[$i]}${undim},"
else
out+="${services[$i]}:,${red}${service_status[$i]}${undim},"
fi
# insert \n every $COLUMNS column
if [ $((($i+1) % $COLUMNS)) -eq 0 ]; then
out+="\n"
fi
done
out+="\n"
printf "\nservices:\n"
printf "$out" | column -ts $',' | sed -e 's/^/ /'