Skip to content

Instantly share code, notes, and snippets.

@wilvk
Created January 1, 2018 02:42
Show Gist options
  • Save wilvk/5c74e490c8132af56c0a01e727b65e21 to your computer and use it in GitHub Desktop.
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
#!/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