Created
March 10, 2018 11:44
-
-
Save ddold/8d98381ce313414ef47301813db7c0b4 to your computer and use it in GitHub Desktop.
Bash script to check if process is 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
#!/bin/bash | |
BLOCKCHAIN=$1 | |
MULTICHAIND=multichaind | |
check_process(){ | |
if [ "$BLOCKCHAIN" = "" ]; | |
then | |
#echo "No blockchain defined in parameter" | |
return 3 | |
fi | |
PROCESS_NUM=$(ps -ef | grep "$MULTICHAIND $BLOCKCHAIN" | grep -v "grep" | wc -l) | |
#$PROCESS_NUM | |
if [ $PROCESS_NUM -eq 1 ]; | |
then | |
#echo "$BLOCKCHAIN is running" | |
return 1 | |
else | |
#echo "$BLOCKCHAIN is not running" | |
return 0 | |
fi | |
} | |
echo "checking if $BLOCKCHAIN is running..." | |
check_process | |
CHECK_RETURN=$? | |
echo "Result after using check_process - $CHECK_RETURN" | |
if [ $CHECK_RETURN -eq 3 ]; | |
then | |
echo "No parameter passed, can't run check" | |
exit 1 | |
elif [ $CHECK_RETURN -eq 0 ]; | |
then | |
echo "$BLOCKCHAIN not started, starting..." | |
nohup $MULTICHAIND $BLOCKCHAIN -d & | |
else | |
echo "$BLOCKCHAIN is already up n running" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment