This is a discussion on Re: Using an awk program within the Sco Unix forums, part of the Unix Operating Systems category; --> Ronald J Marchand wrote: > "Stuart J. Browne" <stuart@promed.com.au> wrote in message > news:413f9da9@dnews.tpgi.com.au... > > > Using an ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Ronald J Marchand wrote: > "Stuart J. Browne" <stuart@promed.com.au> wrote in message > news:413f9da9@dnews.tpgi.com.au... > > > 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????? > > > > So you want the environment variables 'pid' and 'pseudo' after ther fact? > > you can't do that. > > > > You either use ``'s to fill them, or you do everything from within awk. > > > > Example: > > > > #!/usr/bin/awk -f > > BEGIN { > > cmd = "/bin/ps -fU " ENVIRON["logname"] > > while ( cmd | getline ) { > > if ( $8 ~ /xcrt$/ ) { > > pid = $2 > > pseudo = $6 > > system( "<do command here>" ) > > This I will explore. thanks > > > } > > } > > close( cmd ) > > } > > > > If you just want to populate environment variables in a shell for > > lots-of-other-purposes, then you'd have to use it completely differently: > > > > : > > pid=`ps -fU $logname | awk '$8 ~ /xcrt$/ { print $2 }'` > > pseudo=`ps -fU $logname | awk '$8 ~ /xcrt$/ { print $6 }'` > > > > However, if there are multiple PID's for this one, it will only grab the > > 'last' PID/TTY pair. > > I am aware of how to use accent grave to set a variable in the caller. While > this little project has a purpose, it is also a learning project on the use > of awk. I just hoped that if you could pass one piece of information back > to the caller, there could be a way to pass multiple variables. Apparently > not. It seems inefficient to run the same (similar) script several times. Well, there are many ways to pass information back: data files, shared memory, named pipes, and even reading information the called program prints to the screen. There are so many ways to do it that exactly HOW really depends on what your needs are more than anything else. And btw, you would be SO much better off using Perl.. -- Tony Lawrence |
| Thread Tools | |
| Display Modes | |
|
|