Skip to content

Instantly share code, notes, and snippets.

@rishigb
Created May 20, 2016 07:21
Show Gist options
  • Select an option

  • Save rishigb/0faa777eb04ad3d64180a7c2d5aad295 to your computer and use it in GitHub Desktop.

Select an option

Save rishigb/0faa777eb04ad3d64180a7c2d5aad295 to your computer and use it in GitHub Desktop.
#! bash/sh
case "$(pidof sh node.sh| wc -w)" in
0) echo "Starting script; $(date)" #>> /home/ubuntu/code/logs/bot.log
/home/ubuntu/code/fracktalBot/sh node.sh &
;;
1) #all ok
;;
*) echo "Removed double node scripts: $(date)" #>> /home/ubuntu/code/logs/bot.log
kill $(pidof sh node.sh | awk '{print $1}')
;;
esac
#####
for pid in $(pidof -x sh node.sh); do
if [ $pid != $$ ]; then
echo "[$(date)] : node.sh : Process is already running with PID $pid"
exit 1
else
echo "No script is running"
fi
done
#####
if [$(pidof sh node.sh| wc -w)="0"]; then
echo "do something"
elif [$(pidof sh node.sh| wc -w)="1"]; then
echo "Script running"
else
echo "Too many versions of this working, remove a few"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment