Counting Processes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting Processes
# 1  
Old 03-21-2007
Counting Processes

I have a simple script that I want to notify me whenever there are anything other than one instance of a particular process running. I've always used the script:
Code:
DPID_DW=$(ps -ef | grep [d][w] | wc -l)
if [ "${DPID_DW}" -eq 0 ]
   then
        echo "The data warehouse manager for DB is down"
elif [ "${DPID_DW}" -gt 1 ]
  then
        echo "More than one instance of the DW Manager is running"
fi

,,,the problem is that the process is more than a single line. It looks like:

Code:
ps -ef | grep [d][w]
  genret 156098      1   0   Mar 19      - 167:25 /prod/jre_1.3.1/sh/java -Dprgi
d=DWManager -Xms1m -Xmx1024m -Djava.security.policy=/gers/genret/.java.policy -D
xml.catalog.files=/gers/catalog/catalog -cp /gers/genret/opt/path/gerscs.jar:/ge
rs/genret/opt/path/gersdw.jar:/gers/genret/jdbc/lib/classes12.zip:/gers/genret/m
enu/pub/sbin:/gers/genret/menu/pub/bin:/gers/genret/menu/pub/mac:/gers/genret/me
nu/adm/sbin:/gers/genret/menu/adm/bin:/gers/genret/menu/adm/mac:/gers/genret/men
u/sup/bin:/gers/genret/menu/sup/mac:/gers/genret/custom:/gers/genret/fix:/gers/g
enret/src_rev/fix:/gers/genret/opt/path:/gers/genret/bin:/g/bin:/usr/bin:/etc:/u
sr/sbin:/usr/ucb:/sbin -DVERBOSE=n com.gers.dw.DWManager

# 2  
Old 03-21-2007
Er, you should confirm that. The output is spread across multiple lines on screen, but if you check with wc -l or grep -c, you will find that it is on a single line.
# 3  
Old 03-21-2007
I thought the same thing, but I always get "echo "More than one instance of the DW Manager is running" message? Indicating that it is counting more than one line....
# 4  
Old 03-21-2007
Can you actually do an echo of DPID_DW and check the value stored there?
# 5  
Old 03-21-2007
I comes back as "2"?

Code:
x-4-1-user# dw_test
       2
x-4-1-user#

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Error in script while counting processes

Hi all, Below is a script I'm writing and giving me error: #!/usr/bin/sh if ; then echo "Success!" else echo "Failure!" fi Normally if I do ps -ef|grep dw.sap|wc -l it gives me output of 18. So my script checks if it's greater than 17 it echoes success else failure ... (5 Replies)
Discussion started by: frum
5 Replies

2. UNIX for Dummies Questions & Answers

counting?

Hi all, I promise this is my very last dumb question.. but how to you count how many unique names you have. My dataset is: >Bac1 afdsgrr >Bac4 egege >Bac8 dgrjh >Bac1 afdsgrr >Bac1 afdsgrr >Bac8 dgrjh What i want to know is that how many unique names there is, so the output would... (3 Replies)
Discussion started by: Iifa
3 Replies

3. Shell Programming and Scripting

counting using awk

Hi, I want to perform a task using shell script. I am new to awk programming and any help would be greatly appreciated. I have the following 3 files (for example) file1: Name count Symbol chr1_1_50 10 XXXX chr3_101_150 30 YYYY File2: Name ... (13 Replies)
Discussion started by: Diya123
13 Replies

4. Shell Programming and Scripting

help with counting processes, bizzare behavior

I have a ksh script (dtksh Version M-12/28/93d on Solaris 10) that is run daily by cron and sometime hangs forever. I need to detect if there is an old copy hung before I start the new run, and if so send an email and exit the script. Here is part of the code: #!/usr/dt/bin/dtksh... (4 Replies)
Discussion started by: 73rdUserID
4 Replies

5. Shell Programming and Scripting

Counting

Hi, The following output shows how many pmon process are started by users named : oracle or yoavb $ ps -ef |grep pmon |grep -v grep |grep -v ipmon oracle 11268 1 0 Sep 2 ? 36:00 ora_pmon_qerp oracle 17496 1 0 Oct 11 ? 8:58 ora_pmon_bcv oracle 15081 1 0 ... (5 Replies)
Discussion started by: yoavbe
5 Replies

6. Shell Programming and Scripting

Finding the age of a unix process, killing old processes, killing zombie processes

I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time. Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Discussion started by: sukerman
0 Replies

7. Shell Programming and Scripting

Counting

Hi, I want to count how many rows are in a file for a specific column. eg. K NM K NM K NM K JK K NM K JK K NM so the file is tab-delimited. I want to count how many rows are in column 2 and how many NMs there are. I used awk awk '{OFS="\t"}; {count++} {print i,... (3 Replies)
Discussion started by: phil_heath
3 Replies

8. Solaris

Identifying and grouping OS processes and APP processes

Hi Is there an easy way to identify and group currently running processes into OS processes and APP processes. Not all applications are installed as packages. Any free tools or scripts to do this? Many thanks. (2 Replies)
Discussion started by: wilsonee
2 Replies

9. UNIX for Advanced & Expert Users

Monitoring Processes - Killing hung processes

Is there a way to monitor certain processes and if they hang too long to kill them, but certain scripts which are expected to take a long time to let them go? Thank you Richard (4 Replies)
Discussion started by: ukndoit
4 Replies

10. Shell Programming and Scripting

counting characters

Dears, I would like to count the number of "(" and ")" that occur in a file. (syntax checking script). I tried to use "grep -c" and this works fine as long as there is only one character (for which I do a search) on a line. Has anyone an idea how I can count the number of specific characters... (6 Replies)
Discussion started by: plelie2
6 Replies
Login or Register to Ask a Question