Created
July 9, 2020 15:35
-
-
Save 0xMLNK/3a0e323aafba3601271b2934fba4bd97 to your computer and use it in GitHub Desktop.
bash function to start service if it stopped, or stop if running.
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
function checkIt() | |
{ | |
ps auxw | grep -P '\b'$1'(?!-)\b' >/dev/null | |
if [ $? != 0 ] | |
then | |
echo "STARTING "$1; | |
service $1 start; | |
else | |
echo "STOPING "$1; | |
service $1 stop; | |
fi; | |
} | |
#usage | |
checkIt "servicename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment