Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process Reporting 1

Status
Not open for further replies.

gringomike

Technical User
Aug 6, 2003
148
GB
Hi all,

Does anybody have any idea why this script doesn't work? I'm trying to have it report on rogue processes (PID's which return NULL when $VAR2 is executed).


VAR1=`ps -ef |grep VAR2 |grep -v grep |awk '{print $2}'`

for VAR3 in $VAR1
do
COUNT=`ptree $VAR3 |wc -l`
VAR2=`ps -ef |grep $VAR3 |awk '{print $12}'`

if (($COUNT > 2))
then
echo "$FILE is an active process."
else
echo "$VAR2 with process ID $VAR3 is a rogue process."
fi

done


The output is detailed below;

with process ID 20437 is a rogue process.
./script.ksh: 2: not found

TESTI with process ID 28249 is a rogue process.
./script.ksh: 2: not found

TESTN with process ID 28178 is a rogue process.
./script.ksh: 6: not found
with process ID 20473 is a rogue process.
./script.ksh: 6: not found
with process ID 20492 is a rogue process.
./script.ksh: 6: not found


It reports OK when it displays the following line;

TESTN with process ID 28178 is a rogue process.

However it should report the process as being "active" when it displays;

with process ID 20492 is a rogue process.

I also don't understand where these erros are coming from;

./script.ksh: 6: not found AND ./script.ksh: 2: not found

I'm almost sure it's a syntax problem somewhere but I have no idea where!

I hope this makes sense.

Thanks for your help in advance

GM
 
Perhaps a missing $ here...

VAR1=`ps -ef |grep [highlight]$[/highlight]VAR2 |grep -v grep |awk '{print $2}'`

To locate errors use:

ksh -x ./script.ksh



 
Thanks for the reply Ygor!

I'm afraid my naming convention is slightly misleading! I would like to check for the occurrance of "VAR2" when running the "ps -ef" command however I have also called a variable "VAR2".

As such, I have not missed out a "$" by mistake. Sorry for misleading you:-(

Any other ideas?

GM
 
Try to replace this:
if (($COUNT > 2))
by something like this:
if [ $COUNT -gt 2 ]

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top