Re: ps -ef command count value problem from script (490 Views)
Reply
Respected Contributor
RamkumarA
Posts: 216
Registered: ‎06-23-2009
Message 1 of 3 (511 Views)

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.

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 3 (506 Views)

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...

Acclaimed Contributor
Dennis Handly
Posts: 25,275
Registered: ‎03-06-2006
Message 3 of 3 (490 Views)

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?

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.