Created
September 9, 2013 12:25
-
-
Save sobi3ch/6494891 to your computer and use it in GitHub Desktop.
Test if a given process is running. Assuming this form process list (ps).
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 | |
# Save process name to search | |
PROCESS=$1 | |
# Change 'myapp' > '[m]yapp so grep don't count itself | |
GREP_PROCESS=`echo $PROCESS | sed 's/^\(.\)/[\1]/'` | |
# List processes, remove self command name and on the end count wanted process | |
COUNT=$(ps ax | grep -v $0 | grep -c -i $GREP_PROCESS) | |
if [ $COUNT -gt 0 ] | |
then | |
echo Running; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment