Operating System - HP-UX
1752636 Members
6172 Online
108788 Solutions
New Discussion

Re: ps -ef command count value problem from script

 
RamkumarA
Respected Contributor

ps -ef command count value problem from script

 

Hi Experts,

 

I have below script to check process status of bpbkar process. The below $VALUE always returns 2 (or) 3 while executing the script, but when checking the command manually "ps -ef|grep bpbkar | grep -v grep | wc -l" on system, it returns 1. Can somebody help to fix the problem?

 

VALUE=`ps -ef|grep bpbkar | grep -v grep | wc -l`
echo $VALUE
if [ "$VALUE" -gt "1" ]
then
#echo "More than one instance of bpbkar process running"
fi


Output of commands:-

 

odxcdd01:/clocal/csclvl2/user/t1707rd $ ps -ef|grep bpbkar | grep -v grep |wc -l
       1

odxcdd01:/clocal/csclvl2/user/t1707rd $ ps -ef|grep bpbkar | grep -v grep
    root  565400       1  71 23:22:33      - 44:23 bpbkar -r 604800 -ru root -dt 0 -to 0 -clnt odxcdd01.oddc.chrysler.com -class ODD_CGN_FS_AIX -sched Full -st FULL -bpstart_to 300 -bpend_to 300 -read_to 300 -ckpt_time 900 -blks_per_buffer 128 -tir -tir_plus -use_otm -fso -b odxcdd01.oddc.chrysler.com_1320204152 -kl 14 -use_ofb

 

Thanks,
Ram.

2 REPLIES 2
James R. Ferguson
Acclaimed Contributor

Re: ps -ef command count value problem from script

Hi:

 

You don't know what your matching with any assurance -- process basenames, arguments to processes and/or processes whose names contain the string "bpbkar".

 

A much more rigorous way to match is to use the XPG4 (UNIX95) extension with HP-UX 'ps' thusly:

 

# VALUE=$(UNIX95= ps -C bpbkar -opid=|wc -l)

 

This sets the XPG4 (or 'UNIX95') behavior only for the duration of the command line since setting it can have side-effects for other commands that you may not want or know.

The command looks for a process or processes named "bpbkar" in this example and collects the PID value.  THe normal 'ps' heading line is suppressed by using the "=" suffix.

 

Regards!

 

...JRF...

Dennis Handly
Acclaimed Contributor

Re: ps -ef command count value problem from script

>but when checking the command manually

 

Why not put those checking commands in your script to see what it says?

Does your script have bpbkar in its name?