-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path40-services
41 lines (34 loc) · 1021 Bytes
/
40-services
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
#!/bin/bash
# This script displays the status of a list of specified services
# Base version used for this script: https://github.com/yboetz/motd/blob/master/40-services
# set column width
COLUMNS=3
# colors
green="\e[1;32m"
red="\e[1;31m"
undim="\e[0m"
services=("fail2ban" "ufw" "docker" "apache2")
# 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/^/ /'