Skip to content

Instantly share code, notes, and snippets.

@0xMLNK
Created July 9, 2020 15:35
Show Gist options
  • Save 0xMLNK/3a0e323aafba3601271b2934fba4bd97 to your computer and use it in GitHub Desktop.
Save 0xMLNK/3a0e323aafba3601271b2934fba4bd97 to your computer and use it in GitHub Desktop.
bash function to start service if it stopped, or stop if running.
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