Doubt in the daemon running script

Hi
I was going through one of my pjct script .Please let me know the logic for the deamon is running or not as i think the condtn should be vice-versa.

daemon_list = 'idp1278'
FAIL=0
for p in ${daemon_list}
do
  fail=0
  ps -fu  workarea  | grep ${p} > /dev/null 2>&1
  if [[ $? -ne 0 ]] then
    fail=1
    msg="${p} daemon is down"
    print -n "${p} is down"
  else
    msg="${p} daemon is up"
    print -n "${p} is up"
  fi

**where workarea is the hostname .
idp1278 i sthe daemon name .

when the process is running ,it is showing as below command :

ps -fu  workarea  | grep ${p} ->where $p is dp1278
 
workarea 28907 5374 1 02:41:54 pts/14 0:00 grep idp1278 workarea 6058 1 0 00:05:21 ? 0:00 ptr_DmnEnvelope idp1278L idp1278daemon_Sh.

My doubt i s:
1>when ? is coming the process is running actually but in the script it is wriiten if [? is !0 ]then daemon not running .. .what is the actual logic to check the daemon running .

2>ps -fu workarea | grep ${p}/dev/null 2>&1
where $p is idp1278 .

when i executedthe above script nothing came and it took me to next command prompt.At this time the idp12278 daem,on was running in my env .

Also please let me know why this command is used /dev/null 2>&1

Hi,

you can try something like this:

if ps aux | grep '[/]sbin/mydaemon' > /dev/null
then
     echo "mydaemon running"
else
     echo "Its down"
fi

Meaning of:

> /dev/null 2>&1

redirect both stderr and stdout to '/dev/null' (/dev/null is the place to dump anything you don't want, basically this special file discards all data written to it)

You will find a lot of earlier posts on '> /dev/null 2>&1' in this forum. Please search the text 'dev null' on the search box available on top right corner of this page (google custom search to search unix.com)

Hope this helps.