Created
September 5, 2012 17:28
-
-
Save acdimalev/3640605 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cd ~/monitor | |
interval=15 | |
columns=20 | |
pidsfile=/tmp/benjaminr-monitor-pids-$$ | |
statusfile=/tmp/benjaminr-monitor-status-$$ | |
while read service; do | |
echo "? $service" | |
done < services > $statusfile | |
display () { | |
clear | |
while read status service; do | |
if echo "$status" | grep -qv X; then continue; fi | |
for i in $(seq $columns); do | |
c=$(echo $status | cut -b$i) | |
if test "x$c" = 'x-'; then printf '\33[7m\33[32m ' | |
elif test "x$c" = 'xX'; then printf '\33[7m\33[31m ' | |
else printf '\33[0m '; fi | |
done | |
printf "\33[0m $service\n" | |
done < $statusfile | |
} | |
# --- | |
while true; do | |
# --- | |
while read status service; do | |
check/$service > /dev/null & | |
echo "$status $! $service" | |
done < $statusfile > $pidsfile | |
sleep $interval | |
while read status pid service; do | |
if wait $pid; then c='-'; else c='X'; fi | |
status=$(echo "$c$status" | cut -b-$columns) | |
echo "$status $service" | |
done < $pidsfile > $statusfile | |
display | |
# --- | |
done | |
# --- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment