count multiple objects in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting count multiple objects in shell script
# 1  
Old 07-21-2010
count multiple objects in shell script

Hi all:

Trying to count the number of oracle instances on HPUX 11.23 - using ksh. I have multiple instances running and I would like to have a count for how many processes for each instance. Example, run the 'ps -efu oracle' command and for each instance increment a counter. So I am looking for
INT1=# INT2=# INT3=# ... INTn=#

I keep thinking a 'do-while' or some type of 'while' loop but I am missing something, somewhere...

Many thanks!
# 2  
Old 07-21-2010
As a first attempt:

Code:
ps -ef | grep -v awk | awk -F_ '/ora_.*/ {I[$NF]++} END { for( i in I ) print i "=" I[i] }'

I only have one DB locally, it gives:
Code:
DB1=24

But tried it on a productive (albeit AIX) Oracle server and gives the right result too.
This User Gave Thanks to Scott For This Post:
# 3  
Old 07-21-2010
Kinda, sorta. The '_' delimiter is only picking up the ckpt, lgwr, pmon, smon, etc processes. Not getting the connections (LOCAL=). The format of the output is crucial as well since I am wanting to append performance data for nagios. I need the output to look like;
$INT1=# $INT2=# $INT3=# ... $INTn=# | $INT1 $INT2 $INT3 ... $INTn
# 4  
Old 07-21-2010
Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.
You may need to adjust the ps syntax for your Unix platform.

Code:
ps -eu oracle -o args |
  awk 'END {
    for (I in inst)
      print I, "=>", inst[I]
    }
  /^ora(_|cle)/ {
    sub(/^oracle/, null)
    sub(/^.*_/, null)
    inst[$1]++
    }'

Actually, given the requested format:

Code:
ps -eu oracle -o args |
  awk 'END {
    for (I in inst)
	  printf "%s = %d ", I, inst[I]
    printf "%s ", "|"	  
	for (I in inst)
      printf "%s ", I
    print	  
	}
  /^ora(_|cle)/ {
    sub(/^oracle/, null)
	sub(/^.*_/, null)
	inst[$1]++
	}'



---------- Post updated at 09:27 PM ---------- Previous update was at 09:15 PM ----------

On HP-UX you'll need something like this:
Code:
UNIX95= ps -eu oracle -o args |
  nawk 'END {
    for (I in inst)
      printf "%s = %d ", I, inst[I]
    printf "%s ", "|"      
    for (I in inst)
      printf "%s ", I
    print      
    }
  /^ora(_|cle)/ {
    sub(/^oracle/, null)
    sub(/^.*_/, null)
    inst[$1]++
    }'


Last edited by radoulov; 07-21-2010 at 04:20 PM..
These 2 Users Gave Thanks to radoulov For This Post:
# 5  
Old 07-21-2010
Many thanks to both of you. radoulov did the trick.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding total distinct count from multiple csv files through UNIX script

Hi All , I have multiple pipe delimited csv files are present in a directory.I need to find out distinct count on a column on those files and need the total distinct count on all files. We can't merge all the files here as file size are huge in millions.I have tried in below way for each... (9 Replies)
Discussion started by: STCET22
9 Replies

2. Shell Programming and Scripting

Shell script count lines and sum numbers from multiple files

I want to count the number of lines, I need this result be a number, and sum the last numeric column, I had done to make this one at time, but I need to make this for a crontab, so, it has to be an script, here is my lines: It counts the number of lines: egrep -i String file_name_201611* |... (5 Replies)
Discussion started by: Elly
5 Replies

3. Linux

Monitoring shell script if object is down and it should update the child objects status as well

Viewers Please help me to get out of the below issue.. Thanks in advance Required shell script for Monitoring status of the objects and it should update the child objects status as well. Requirements:- 1. We are working on IIB (IBM Integration Bus v10) and trying to implement the broker ('... (0 Replies)
Discussion started by: dsreddy447
0 Replies

4. Shell Programming and Scripting

File Count Based on FileDate using Shell Script

I have file listed in my directory in following format -rwxrwxr-x+ 1 test test 4.9M Oct 3 16:06 test20141002150108.txt -rwxrwxr-x+ 1 test test 4.9M Oct 4 16:06 test20141003150108.txt -rwxrwxr-x+ 1 test test 4.9M Oct 5 16:06 test20141005150108.txt -rwxrwxr-x+ 1 test ... (2 Replies)
Discussion started by: krish2014
2 Replies

5. Linux

How to store count of multiple queries in variables in a shell script?

how to store the count of queries in variables inside a filein shell script my output : filename ------- variable1=result from 1st query variable2=result from 2nd query . . . . (3 Replies)
Discussion started by: sanvel
3 Replies

6. Shell Programming and Scripting

Shell Script for viewing multiple logs from multiple server

I am new to Shell scripting and below is my requirement. I need to search some specific word e.g. "exception" or "transaction" from log file. We have multiple env e.g. Level1 , Level2 etc and each env have Multiple boxes e.g. For Level 1 env we have "test11.test.com" , "test12.test.com". Each... (1 Reply)
Discussion started by: peeyush
1 Replies

7. Shell Programming and Scripting

Hit count on a shell script

I have a unix shell script (ex.sh) written. How to find out how many users (incl. myself) have run this .sh ? I can insert code snipet at top of script if need be. - Ravi (2 Replies)
Discussion started by: ravi368
2 Replies

8. Shell Programming and Scripting

shell script to get the arrival count of file

Hello All, I have come across a small problem. It would be great if any of you could help me in resolving the issue. one file named dummy.txt will be ftped to Unix machine twice daily. If i receive it second time in a day i need to do some processing with the file. How to find the... (2 Replies)
Discussion started by: RSC1985
2 Replies

9. Shell Programming and Scripting

PERL: Replace multiple objects within a string

looking to replace parameters within a string with an external answer - with multiple replacements within a string %% will be used to wrap the objects to be replaced i.e. hello %%title%% %%user%% from %%address%% you last %%action%% on %%object%% the params will be used to make calls to a... (1 Reply)
Discussion started by: bidbrooken
1 Replies

10. UNIX for Dummies Questions & Answers

Perl/shell script count the lines

Hi Guys, I want to write a perl/shell script do parse the following file input file content NPA-NXX SC 2084549 45 2084552 45 2084563 2007 2084572 45 2084580 45 3278411 45 3278430 45 3278493 530 3278507 530... (3 Replies)
Discussion started by: pistachio
3 Replies
Login or Register to Ask a Question