How to fetch running/failed process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to fetch running/failed process
# 1  
Old 03-06-2009
How to fetch running/failed process

I am trying to fetch failed process but while doing that unable to do so. like;

(1)ps -ef | grep snmpCollect

o/p is coming like -

root 12423 4393 1 19:44:06 pts/0 0:00 grep snmpCollect

(2)ps -ef | grep sttps

o/p-

root 15517 4393 0 19:53:24 pts/0 0:00 grep sttps
root 10900 10822 5 13:02:43 ? 1:38 sttps -P -k segRedux=true

That means process snmpCollect is not running and process sttps is running.


Now ,I want a logic that tell process snmpCollect is not running

For that,I am trying following command-

p_name=`ps -ef | grep $process_name | grep -v "grep" | awk '{print $9}'`

if [[ -n $p_name ]];
then
echo "$process_name is Running "
else
echo "$process_name is Down"
fi


but this one is not working properly.I know there is something I can do with awk.


Thanks in advance!!!!
# 2  
Old 03-06-2009
Do you want another way to test if the process is running ?

Try this:

Code:
ps -ef | grep $process_name | grep -v "grep" > /dev/null 
if [ $? -eq 0 ]
then
    echo "$process_name is Running "
else
    echo "$process_name is Down" 
fi

# 3  
Old 03-06-2009
thnx yaar !!! thats working


one more thing what the significance of >/dev/null

whr can I see that??
# 4  
Old 03-06-2009
Code:
 
ps -ef | grep $process_name | grep -v "grep" > /dev/null

Since I'm testing the exit code of the command ($?) I don't really need the output so I send it to /dev/null which is a kind of garbage can.

exit code 0 means the command ends successfully ( find a process in this case) other value may mean different thing depends on the command.
# 5  
Old 03-06-2009
Quote:
Originally Posted by ce9888
Do you want another way to test if the process is running ?

Try this:

Code:
ps -ef | grep $process_name | grep -v "grep" > /dev/null 
if [ $? -eq 0 ]
then
    echo "$process_name is Running "
else
    echo "$process_name is Down" 
fi

'man ksh' yields the following:
Code:
     ?     The decimal value returned by the last  executed  com-
           mand.

In your case 'grep -v grep'
# 6  
Old 03-06-2009
Quote:
Originally Posted by vgersh99
'man ksh' yields the following:
Code:
     ?     The decimal value returned by the last  executed  com-
           mand.

In your case 'grep -v grep'
Logicaly you are right how can you explain this :

Code:
ce9888$ ps -ef | grep -i fiha                                
    user  37558      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
  ce9888  41702  50948   0 10:57:09 pts/12  0:00 grep -i fiha 
    user  56818      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    user  65156      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    user  66926      1   0 08:50:57      -  0:00 /home/s/sys/fiha 
    user  67088      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    user  67470      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    user  68270      1   0 08:50:57      -  0:00 /home/s/sys/fiha 
    user  68366      1   0 08:50:57      -  0:34 /home/s/sys/fiha  
    user  68980      1   0 08:50:57      -  0:00 /home/s/sys/fiha
    user  72298      1   0 08:50:57      -  0:05 /home/s/sys/fiha
ce9888$ echo $?
0

Code:
ce9888$ ps -ef | grep -i fiha | grep -v grep                 
    user  37558      1   0 08:50:57      -  0:00 /home/s/sys/fiha 
    user  56818      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    user  65156      1   0 08:50:57      -  0:00 /home/s/sys/fiha 
    user  66926      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    user  67088      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    user  67470      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    user  68270      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    user  68366      1   0 08:50:57      -  0:36 /home/s/sys/fiha 
    user  68980      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    user  72298      1   0 08:50:57      -  0:05 /home/s/sys/fiha  
ce9888$ echo $?
0

It reacts as you suggest, since grep -v did find the "grep" string.

Code:
ce9888$ ps -ef | grep -i fiha | grep -v toto
  ce9888  36474  50948   1 11:08:21 pts/12  0:00 grep -i fiha 
    spsy  37558      1   0 08:50:57      -  0:00 /home/s/sys/fiha
    spsy  56818      1   0 08:50:57      -  0:00 /home/s/sys/fiha 
    spsy  65156      1   0 08:50:57      -  0:00 /home/s/sys/fiha 
    spsy  66926      1   0 08:50:57      -  0:00 /home/s/sys/fiha 
    spsy  67088      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    spsy  67470      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    spsy  68270      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    spsy  68366      1   0 08:50:57      -  0:37 /home/s/sys/fiha  
    spsy  68980      1   0 08:50:57      -  0:00 /home/s/sys/fiha  
    spsy  72298      1   0 08:50:57      -  0:06 /home/s/sys/fiha  
ce9888$ echo $?
0

Accordingly to your assumption this one should have return 1 since grep -v didn't found the "toto" string. which its not the case...
# 7  
Old 03-06-2009
I've observed a very similar behavior under Solaris as well - no, I cannot reconcile it with the 'man' pages and my understanding of pipes/processes.
Maybe others can chime in.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

2. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (6 Replies)
Discussion started by: naveeng
6 Replies

3. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (1 Reply)
Discussion started by: naveeng
1 Replies

4. BSD

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies

5. HP-UX

How to fetch all running services on HP-UX?

Hi All, I have a requirement to get all the running services on few HP-UX boxes. In Linux systems I am able to do that successfully using: chkconfig --list. However I can't find anything equivalent in HP-UX. If anyone has any pointers on the same then please suggest. Adyan (4 Replies)
Discussion started by: Adyan Faruqi
4 Replies

6. Programming

Fetch running applications list in Linux

Hi, I need to write a code which will fetch all the application activity on user computers including app name, time of day, duration, version, etc. Using this I need to know which applications are running currently in user's computers. How can it be done programmatically? I need to write the... (1 Reply)
Discussion started by: arunarora
1 Replies

7. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

8. Filesystems, Disks and Memory

skgpspawn failed running oracle db 9.2.0.5.0 on aix 5.3

Hi, I am running an oracle db 9.2.0.5.0 on ibm p5 550 aix 5.3 with 10g ram, 10G swap space 3 database instances each SGA about 500Meg. I am getting the following error in my alert log file from time to time: skgpspawn failed:category = 27142, depinfo = 11, op = fork, loc = skgpspawn3 ... (0 Replies)
Discussion started by: hawkerpacific
0 Replies

9. Shell Programming and Scripting

Editing file during running ksh in HP failed

Hi falks, I have the following program: #!/bin/ksh ed -s /home/ias/v9.0.3/j2ee/OC4J_RiGHTv_HPCD2/applications/Xbip/Xbip/WEB -INF/config/application.properties <<EOF >/dev/null 1 d . d . a application.filePath.core = /core-HPCD2/Html/ application.filePath.xbip =... (2 Replies)
Discussion started by: nir_s
2 Replies

10. UNIX for Dummies Questions & Answers

Unix Process Failed

Im having this problem ever since im Using Unix. Please help.Im using Linux Red Hat 7.0. 2.2.6. My Problem is. Whenever i close my unix before the system goes to Halt mode and stoping all md device, this Process shows me as fail. : Saving Mixer settings modprobe: modprobe: can't locate module... (1 Reply)
Discussion started by: killerserv
1 Replies
Login or Register to Ask a Question