Doubt in the daemon running script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Doubt in the daemon running script
# 1  
Old 08-02-2010
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.

Code:
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 :
Code:
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

Last edited by pludi; 08-02-2010 at 05:49 AM..
# 2  
Old 08-02-2010
Hi,

you can try something like this:

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

Meaning of:
Code:
> /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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to write a daemon script?

My requirement is to run two scripts simultaneously. Let say, script1.ksh is running in a loop : example: script1.ksh is: for i in 1 2 3 do script2.ksh 1 & #psedu code which is required to write here # if script 2.ksh is running, execute a script3.ksh (which actually check the... (2 Replies)
Discussion started by: sumitc
2 Replies

2. AIX

Alert: Network Status Monitor daemon (rpcstat) is not running

Hi I am currently testing SCOM2012 on my AIX systems for monitoring. I tested it on 3 systems and immediately i got the following errors: Alert: Network Status Monitor daemon (rpcstat) is not running Source: AIX 7.1 Path: (left blank) Last modified by: (left blank) Last modified time:... (3 Replies)
Discussion started by: jsabo40
3 Replies

3. UNIX for Dummies Questions & Answers

Oracle process running as user daemon

Hi, When process listing, I came across a process running as user daemon. daemon 23576 23574 0 07:32:04 ? 0:07 oracle (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) root 27526 27444 1 07:38:43 ttyp5 0:00 grep 23574 why a process runs as user daemon, when it should be... (3 Replies)
Discussion started by: wilsonee
3 Replies

4. Solaris

Gnome config daemon gconfd-2 running out of file descriptors

Hello, I need to increase the maximum number of open files for the Gnome configuration daemon, /usr/lib/gconfd-2. There is one of these for each username, no matter how many sessions they've got. We have lots of people using DTUs to log into a Sun Ray server using the same account (bad idea,... (3 Replies)
Discussion started by: Twirlip
3 Replies

5. Shell Programming and Scripting

script to run as a daemon

Hi, I have one query that is suppose if I have a script that pick up some files from source folder and put it into destination folder , and I want this script to run after every 1 hour, to make it configurable as per that I have options like crontab and nohup but when I test this script I have to... (2 Replies)
Discussion started by: nks342
2 Replies

6. Shell Programming and Scripting

Find hangs with automountd daemon running

Hi, I am trying to find files with specific name using find / -name core -print.. this command is hanging and never completes as it is searching for all the automount filesystems ..i cant eliminate using "! -fstype nfs" as this is not a nfs filesystem pls let me know if anyone know how to... (2 Replies)
Discussion started by: to_bsr
2 Replies

7. Solaris

Port status/Running daemon

Hi, I need to run an application (Hudson) listening to port 8080 on a remote Solaris server. I have managed to start that application and tried to access it with my browser from my local PC, but unsuccessfully. I need to find out what is blocking the access to that port (or any other). A... (9 Replies)
Discussion started by: JVerstry
9 Replies

8. Solaris

doubt reg syslogd daemon

can anyone explain what is syslogd daemon in solaris. What is the use and how to start and stop the syslogd. (3 Replies)
Discussion started by: rogerben
3 Replies

9. Shell Programming and Scripting

Doubt in running shell script

Hi, I'm a newbie in shell script. I have a problem in running my a.out in a bash shell script named vetri . The following is the code. #!bash/bin ./a.out abc.xyz where ./a.out is a c++ bin file and abc.xyz is an argument. My ./a.out expects an input (cin >> temp). How can I give the... (5 Replies)
Discussion started by: lchokka
5 Replies

10. UNIX for Dummies Questions & Answers

daemon running in AIX checking

how do u check if a daemon is running in AIX.. Is it ps -ef|grep daemon lssrc -s demon ??? Thanks! (0 Replies)
Discussion started by: karthikosu
0 Replies
Login or Register to Ask a Question