Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Check if not running then start (See related posts)

// This is to check if a process is running. Used with my bot

#!/bin/sh
# Check if bot is runing then exit otherwise restart
# put in crontab
# 0,10,20,30,40,50 * * * * /path/to/check.sh


MYPATH=/path/to

PID=0

if test -r $MYPATH/bot.pid; then
	PID=$(cat $MYPATH/bot.pid)
fi

if [ 0 -ne $PID ]; then
	running=`ps --pid $PID | grep $PID |wc -l` 

	if [ $running -eq 1 ]; then
		exit 1 
	fi
fi

cd $MYPATH
./check.sh & >/dev/null


You need to create an account or log in to post comments to this site.