The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
process status nicos High Level Programming 3 12-09-2008 01:52 PM
List Process with their Status. varungupta UNIX for Advanced & Expert Users 2 03-21-2008 09:27 PM
Ftp Service /process Status GaneshB Linux 1 03-10-2008 10:15 AM
replace first instance(not first instance in line) IronHorse7 Shell Programming and Scripting 3 02-07-2008 01:29 PM
How to check if another instance of the process is running sim Shell Programming and Scripting 8 06-30-2005 07:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-02-2009
yoursdavinder yoursdavinder is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 21
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 (permalink)  
Old 02-02-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,262
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 (permalink)  
Old 02-02-2009
yoursdavinder yoursdavinder is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 21
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 | OC4Jc4j_soa |21240 | Alive
HTTP_Server | HTTP_Server |21239 | Alive

Thanks in advance. Appreciate your help...
  #4 (permalink)  
Old 02-02-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,262
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 (permalink)  
Old 02-11-2009
yoursdavinder yoursdavinder is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 21
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 (permalink)  
Old 02-11-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,262
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0