Skip to content

Instantly share code, notes, and snippets.

@Sherex
Created February 28, 2019 18:11
Show Gist options
  • Save Sherex/dc1bb20f10dee3c1ccc72eeb8737046b to your computer and use it in GitHub Desktop.
Save Sherex/dc1bb20f10dee3c1ccc72eeb8737046b to your computer and use it in GitHub Desktop.
#!/bin/bash
# This was created to be used as a service overview in the motd on a Debian system.
# But use it as you like.
# Add service names in this array
services=( "videoserver" "hostapd" "isc-dhcp-server" )
echo " "
echo "SERVICES"
join() {
# $1 is return variable name
# $2 is sep
# $3... are the elements to join
local retname=$1 sep=$2 ret=$3
shift 3 || shift $(($#))
printf -v "$retname" "%s" "$ret${@/#/$sep}"
}
servicesStatus=()
maxChar=0
for service in "${services[@]}"
do
if [ "${#service}" -gt "$maxChar" ]; then
maxChar="${#service}"
fi
done
for service in "${services[@]}"
do
status="$(/bin/systemctl is-active $service)"
servicesStatus+=("$status")
spaces=()
for i in $(seq ${#service} $maxChar);
do
spaces+=("\x20")
done
join spacesJoined "" ${spaces[*]}
printf "$service:$spacesJoined[ $status ]\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment