1754016 Members
7762 Online
108811 Solutions
New Discussion юеВ

Re: script help

 
SOLVED
Go to solution
Petra Sandberg
Advisor

script help

Hi, I've created a script that put PID's in a variable,
(PC='ps -fu petra | grep process | cut -c 14-20') now I want to match this output whit the PPID of the process, so that if the PPID is a specific number then do something.

Any suggestions on how to...

Rgds
Petra
2 REPLIES 2
Stefan Farrelly
Honored Contributor
Solution

Re: script help

Once you have your pid in $PC then;

ps -fp $PC | awk '{print $3}' | grep -v PPID

returns the PPID of pid $PC
or you enclose the whole thing above into another variable;
PPID=$(ps -fp $PC | awk .....)
Im from Palmerston North, New Zealand, but somehow ended up in London...
Robert Thorneycroft
Valued Contributor

Re: script help

You should use awk to pull out the value you want as cut can give wrong values in the way you are using it.

ie on my system
ps -fu root | grep opcmona | cut -c 14-20
Give output of.
2 10702

Where the value of 2 is actually the last digit of the PID and the other numbers are the PPID you are after.

You should use:

PID=`ps -fu petra | grep process | awk '{ print $2 }'`
PPID=`ps -fu petra | grep process | awk '{ print $3 }'`

For an individual process this shoould work perfectly to give you both values you require.

Kind regards,

Robert Thorneycroft