script to check if process is running

How do I make a shell script to see if a certain process is running.

The process shows up on

ps aux 

as /usr/sbin/daemon

eg:

if [! /usr/sbin/daemon ]
/usr/sbin/daemon
else
#nothin

basically i want to run the process if it isnt running/ has been stopped.

Thanks.

if ps aux | grep '[/]usr/sbin/daemon'
then
     echo Running
else
     /usr/sbin/daemon &
fi

thanks alot thats exactly what i needed, probably would have taken me ages to work out how to use grep!

works perfectly.

1 Like