View Single Post

   
  #6 (permalink)  
Old 02-15-2008, 04:07 PM
Ronald J Marchand
 
Posts: n/a
Default Re: Using an awk program

"Jean-Pierre Radley" <jpr@jpr.com> wrote in message
news:20040909002807.GB22610@jpradley.jpr.com...
> Ronald J Marchand typed (on Wed, Sep 08, 2004 at 06:32:24PM -0500):
> | Using an awk program, I am trying to set the values of pid and pseudo in

a
> | shell script to be used in other commands. So far I have:
> | :
> | logname=digna
> | pid=
> | pseudo=
> | ps -ef | grep xcrt | awk -v user=$logname -v pid=$pid -v pseudo=$pseudo

'
> | ( $1 == user && $8 == "/usr/lib/merge/xcrt" ) { print $1,$2 }
> | ( $1 == user && $8 == "/usr/lib/merge/xcrt" ) { pid = $2 }
> | ( $1 == user && $8 == "/usr/lib/merge/xcrt" ) { pseudo = $6 }
> | '
> | echo $pid
> | echo $pseudo
> | exit
> |
> | This program executes fine. It just doesn't set pid & pseudo.
> | Could some kind soul show mercy and explain the error?????
>
> A parent does not inherit from its child. Whatever you set inside the
> awk program is unknown outside it.
>
> Your grep is superfluous, BTW.


You are in fact correct. I started building from what I used on the command
line.

>
> Try this:
>
> eval `ps -ef | awk -v user=$LOGNAME '
> $1~user && $8~"/usr/lib/merge/xcrt" {print "pid=" $2 " pseudo=" $6}
> '`
> echo PID is $pid and PSEUDO-TTY is $pseudo


In this case I am writing a script to do a job which requires 2 variables.
I can execute the awk program twice with accent grave to set the variables.
But what if you wanted 6? Apparently you can direct the output to a file
( I have never done it ... yet). I was hoping there was a way to redirect
this back into the script without using a file.

Thanks
Ron


Reply With Quote