Created
January 1, 2018 02:42
-
-
Save wilvk/5c74e490c8132af56c0a01e727b65e21 to your computer and use it in GitHub Desktop.
bash script to test if a process is running and do an action if it is or isn't
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/bash | |
PROCESS_GREP_STRING=eth | |
PROCESS_COUNT_THRESHOLD=3 | |
SLEEP_TIMEOUT=5 | |
RUNNING_COMMAND="echo 'Running'" | |
NOT_RUNNING_COMMAND="echo 'Not Running'" | |
while : | |
do | |
PROCESS_COUNT=$(ps a|grep $PROCESS_GREP_STRING|wc -l) | |
if [ "$PROCESS_COUNT" -ge "$PROCESS_COUNT_THRESHOLD" ] | |
then | |
eval $RUNNING_COMMAND | |
else | |
eval $NOT_RUNNING_COMMAND | |
fi | |
sleep $SLEEP_TIMEOUT | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment