forked from 40Cakes/PlexMOTD
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path11-process-check
executable file
·36 lines (31 loc) · 1 KB
/
11-process-check
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
#!/bin/bash
MY_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${MY_PATH}/config.conf"
# Check for services file from config.conf.
if [ -f "${SERVICEFILE}" ]; then
readarray -t SERVICES < "${SERVICEFILE}"
# Check to see if we have a service file in the directory where the script is run.
elif [ -f "${MY_PATH}/services" ]; then
readarray -t SERVICES < "${MY_PATH}/services"
# We don't have a service file, lets default to just checking for plex.
else
SERVICES=(
"plexmediaserver"
)
fi
service_check(){
STATE=$(service $1 status | grep "active (running)" | wc -l)
if [ "$STATE" = "1" ]; then
echo -e "${GRN}OK!${NC}"
else
echo -e "${RED}Not running...${NC}"
fi
}
pad=$(printf "%0.1s" "${PAD_CHARACTER}"{1..60})
for index in "${!SERVICES[@]}"; do
printf " ${YEL}%s " "${SERVICES[index]}"
SERVICE_LENGTH=${#SERVICES[index]}
STATE=$(service_check "${SERVICES[index]}")
STATE_LENGTH=${#STATE}
printf "%*.*s${NC} ${STATE}\n" 0 $((PAD_LENGTH - SERVICE_LENGTH - STATE_LENGTH)) "$pad"
done