Printing the Status of a Process in an Instance


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing the Status of a Process in an Instance
# 1  
Old 02-02-2009
Printing the Status of a Process in an Instance

Hi,

I am executing the command: "./opmnctl status" to get the status of the processes in the instance. There are totally 5 processes that are avaialble, out of which 3 are "Alive" and 2 are "Down". How can I use the IF loop to get the status and echo it??

For instance I want to run a check whether all the processes are "Alive" if yes then echo saying "OPMN is up" else "Not all OPMN processes are up"

Please help.

Thanks.
# 2  
Old 02-02-2009
You can either just grep for the pattern you'd like not to find, in this case "Down" and test it's $? with if/then/fi to decide what to do.

Also to be more flexible you could do it like this:
Code:
root@isau02:/data/tmp/testfeld> cat infile
Alive process_one
Alive process_two
Down  process_three
Down  process_four
Alive process_five


awk '/^Alive/ {c+=1} END{if ( c != NR ) {print "not all processes are up"} else {print "all fine"} }' c=0 infile
not all processes are up

There are many ways to do this of course.
# 3  
Old 02-02-2009
Thanks for your reply....
I am actually new to working with Unix...Could you please explain in detail??
Following is how im getting the process details:

[root@SNRBBY34844 bin]# ./opmnctl status
Processes in Instance: oc4j_as1.mxb01981s001.naretail.na.com
---------------------------------+--------------------+---------+-----
ias-component | process-type |pid | status
---------------------------------+--------------------+---------+-----
ASG | ASG |N/A | Down
OC4JGroup:default_group | OC4J:IP-BO-C-I~ |21242 |Alive
OC4JGroup:default_group | OC4J:P-BO-M10 |N/A | Down
OC4JGroup:default_group | OC4JSmiliec4j_soa |21240 | Alive
HTTP_Server | HTTP_Server |21239 | Alive

Thanks in advance. Appreciate your help...
# 4  
Old 02-02-2009
If you post code, logs, data etc. use code-tags for better readability please.

Ok, processing the relevant part of your output:
Code:
awk -F"|" '
      $NF ~ /Alive/ {r+=1; a+=1; print}
      $NF ~ /Down/ {r+=1; d+=1; print}
END{if( a != r ) {print "some not up!"}}
' infile

ASG | ASG |N/A | Down
OC4JGroup:default_group | OC4J:IP-BO-C-I~ |21242 |Alive
OC4JGroup:default_group | OC4J:P-BO-M10 |N/A | Down
OC4JGroup:default_group | OC4Jc4j_soa |21240 | Alive
HTTP_Server | HTTP_Server |21239 | Alive
some not up!

  1. Setting | as field separator
  2. $NF is the last field, checking if it contains the pattern Alive
  3. If so, the stuff in the curly braces is being done, ie. it increases the record counter r by +1 and the Alive counter a by 1. With the record counter we track how many rows we processed over all.
  4. If it doesn't find the pattern "Alive" in the last field, it will use this line and check $NF for the pattern "Down". It increases the record counter by 1 and the Down counter d. The Down counter is not necessary but maybe for future use.
  5. In the end, when all lines are processed, it checkes the variables and if the Alive counter is not equal the number of processed relevant rows/records, it will spit an error message as you can see.

All other lines that don't fit to the 2 rules $NF ~ /Alive/ or $NF ~ /Down/ are just bypassed.

Last edited by zaxxon; 02-02-2009 at 12:18 PM.. Reason: Exploring the LIST-tag :)
# 5  
Old 02-11-2009
I am trying to execute the set of code u have provided by putting it in a script file for e.g. "Test.sh" and when I am executing the script I get a following error:

awk: cmd. line:2: -
awk: cmd. line:2: ^ unexpected newline or end of string


Can u pls. help?? Thanks in advance...
# 6  
Old 02-11-2009
If you are on Solaris use /usr/xpg4/bin/awk. Else you might check if you have gawk or nawk.

I just checked the code again with gawk, no problem, works flawless.
# 7  
Old 02-11-2009
I am on Linux machine...I tried using gawk but I get the same error...

gawk: cmd. line:2: -
gawk: cmd. line:2: ^ unexpected newline or end of string

Please suggest....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to check a single process instance is always running?

Hi, I want to write one program in C in Unix OS which will check the running status of a process time to time. If the process is stopped somehow by any means, it will ensure that the process is restarted and only one copy of the process image should run in memory at any point of time for the user.... (2 Replies)
Discussion started by: sanzee007
2 Replies

2. Shell Programming and Scripting

Process Instance not running properly.

I have run 10 instances of the process eg, process name is BG nohup /WP01IRB1_irbapp/IRBWPROD/RB/bin/BG -c 1 -t 23 -a '-caTop TESTBILLCYCLE='5FEB13_81PT19NPT''>a.txt & nohup /WP01IRB1_irbapp/IRBWPROD/RB/bin/BG -c 2 -t 23 -a '-caTop TESTBILLCYCLE='5FEB13_81PT19NPT''>b.txt & nohup... (3 Replies)
Discussion started by: ankitknit
3 Replies

3. Shell Programming and Scripting

How to check the process status

Hi, I have a cron job which runs every ten minutes, now i hav to check the process whether it is running or not only once and then this should be sent to a log file.. crontab : 00,10,20,30,40,50 * * * * a process check ps = 'ps -ef |grep a ' if then echo " Success" >... (3 Replies)
Discussion started by: NehaKrish
3 Replies

4. UNIX for Advanced & Expert Users

Multiple Instance Of Same Process

Hi Everyone, I am using solaris 5.10. I have a java process running in server mode in unix. The problem is that it automatically forks i.e creates a child process. I mean suddenly two instances of that process start running , in which the process-id of first instance is the parent... (5 Replies)
Discussion started by: glamo_2312
5 Replies

5. UNIX for Dummies Questions & Answers

Multiple instance of same process

;)Hi Everyone, I am using solaris 5.10. I have a java process running in server mode in unix. The problem is that it automatically forks i.e creates a child process. I mean suddenly two instances of that process start running , in which the process-id of first instance is the parent... (0 Replies)
Discussion started by: glamo_2312
0 Replies

6. UNIX for Advanced & Expert Users

Status of a Linux process

All, I have fair amount of knowledge about shell scripting, but only liitle on system administration. I would like to know how to analyze whether the particular linux process is alive or not ? If it is alive, will it affect the performace of other process ?. Also is it still consuming... (1 Reply)
Discussion started by: apsprabhu
1 Replies

7. Programming

process status

hello everybody!! i want to post a question! is there any way to get process status using C commands? To be more specific, i want to know whether a process is running or is stop or killed. thanks in advance! (3 Replies)
Discussion started by: nicos
3 Replies

8. UNIX for Advanced & Expert Users

Getting status of a signal in process?

Hi all, How can a process be aware of the signals it handles. I looked at available signal API, but couldn't find any help. If a process defines it own handler for a signal, the default handler for that signal becomes overridden. I am interested in getting to know the... (2 Replies)
Discussion started by: bluehive
2 Replies

9. Shell Programming and Scripting

How to check if another instance of the process is running

Hi, I am writing a shell script to invoke a C++ program. Before I start the C++ program (oi7loadbalancer), I am checking if the process is already running. I start the process only if it is not already running. I have the following check in my script. proccount=`ps -f -u $USER_NAME | grep... (8 Replies)
Discussion started by: sim
8 Replies

10. AIX

Process status display

On AIX 5.2, I use "ps -ef " command to display the process status, the field of command looks like: , the detailed contents are: # ps -ef |grep rtesfmrt Display: osa 32455 1 0 18:20 - 1:57 The origianl format shoud be: osa 32455 1 0 18:20 - 1:57 ... (2 Replies)
Discussion started by: Frank2004
2 Replies
Login or Register to Ask a Question