1850404 Members
1996 Online
104054 Solutions
New Discussion

Re: About the script

 
sunhui
New Member

About the script

I have below program to find the process "orapp" and echo the result ,

if
xxxx
then
for x in `ps -ef |grep "orapp" |awk { print $2; }

do
echo $x
done
else
xxxx
fi

now if I want to add one more condition - if the IP address of the process
is 192.168.0.1 ( who -u |awk { print $8} , how can I mix these two
condition into one script ? thx.
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: About the script

Hi:

Give you have "X":

# who -u|awk -v x=192.168.0.1 '$8~x {print}'

...will print the matching entry from 'who'.

Regards!

...JRF...
sunhui
New Member

Re: About the script

thx james ,

but how to mix with the above script ? thx
Kent Ostby
Honored Contributor

Re: About the script

if
xxxx
then

touch .mytemp
rm .mytemp
ps -ef | awk '/orapp/{print "ps", $2}' > .mytemp
who -u | awk '/192.168.0.1/ {print "who",$7}' >> .mytemp
awk '/^ps/ {keepid[$2]=1;next} {if (keepid[$2]==1) {print $2};}' < .mytem

else
xxxx
fi
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
James R. Ferguson
Acclaimed Contributor

Re: About the script

Hi:

I'm not sure what you want to do. First, using 'grep' to match a process is prone to matching the wrong process. You should use:

# UNIX95= ps -C orapp -o pid,usr,tty

This will find all processes whose *basename* (command) is equal to "orapp". The output of matching processes will include the pid, the user, and the associated tty (if any).

From that, you would match the 'tty' to the 'tty' found in the output of 'who'. You could also match the 'pid' values.

Does this now help?

Regards!

...JRF...
sunhui
New Member

Re: About the script

thx replies,

may be my question is not clear , I just want combine the above two condition into one script , is that possible ? thx