Created
September 3, 2013 17:07
-
-
Save jjrh/6426651 to your computer and use it in GitHub Desktop.
Checks if mpd and mpdscribble are running, if not start them up.
check_prog function will also work to check/start any program
This file contains 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 | |
# checks if a program is running, if not, it tries to start it. | |
# after 3 tries, if the program hasn't started we print out the error | |
# and return. | |
errors="" | |
check_prog () | |
{ | |
if [ $count -eq 3 ] | |
then | |
printf "\t *** issue starting:'$1',\t '$errors' \n" | |
return | |
else | |
count=$(expr $count + 1) | |
fi | |
if [ $(pgrep -x "$1") ] | |
then | |
printf "\t * %-20s (running: %10s\n" "$1" "pid: $(pgrep -x "$1"))" | |
else | |
if [ $count -eq 1 ] | |
then | |
printf "\t * $1 not running, starting up\n" | |
fi | |
errors=$($1 2>&1) | |
check_prog $1 | |
fi | |
} | |
count=0 | |
check_prog mpd | |
count=0 | |
check_prog mpdscribble |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment