|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hey guys,
The foll. awk script(stored in filename.awk) is not working properly. In line 2 i store the output of the 'ps-fade' command in a file called op... then i use a pattern to get the PPID( parent PID) and store it in variable 'var' using getline... Till line 3 everything is okay. Line 3 prints the value of the PPID correctly. But when i use 'var' in the line 4 , the output of "top" isnt directed into the file "opt" . It's as if 'var' cant be accessed in line 4.. Only the value of var is printed(line 3) in "opt" file.. By the way the command inside the system function works fine on the command line,but not when i use the the command "awk -f filename.awk" to get the behavior i want the code ---> 1 BEGIN { 2 "ps -fade >op; awk '/some pattern/ {print $3}' op " | getline var 3 print var,"\n" 4 system("top -b -d 1 $(awk '$3 == var {print \" -p\" $2}')" ) > "opt" } by the way in line 4 im trying to get only those processes printed in "opt" whose PPID is given by 'var' |
|
#2
|
||||
|
||||
|
Sorry, but it looks like you're trying to cut down trees with a breadknife. You really should consider using Perl for this stuff.
christo
__________________
. Spiration channels: Free scripts, programming tutorials and articles Dotcut alerts: Online Press cuttings / news alerts Clearprop: UK microlight school, wiltshire Uk dating: UK safe dating with Topdates About Christo . . |
|
#3
|
|||
|
|||
|
Quote:
post the output of your ps cmd your OS ?
__________________
working on Solaris[5-9], preferred languages french and C. |
|
#4
|
|||
|
|||
|
Quote:
Hello, your problem is in the system function. Read the 'man awk' carefuly and you will see that this function is exactly the same as the system C-function: it forks a new copy of Bourne shell which gets your string to interpret. So your process generates a child proces, whose standard output the father process cannot see. You get the output from the system command on your terminal, no matter how you try to redirect it. The only possibility how to get output from 'top' (and not only top but any command) to your awk script proces is as follows: CMD="top -p \"3496\" " while (CMD | getline > 0) { print $0 # do any processing of the line here } close(CMD) The same holds for all flavours of Unix. Quite simple if you know it, isn't it? I have made the same error many years ago, too.... Regards ![]() |
|
#5
|
|||
|
|||
|
A confusion
Excuse me, but I have a doubt in the reson that has been given by zlutovsky. Even if a process forks or uses a fork-exec pair to create a child process, the child process still accesses the same control terminal and this is true for shell also. So we can easily direct the output of top command to any file. But the problem lies in the fact that, probably the format of the output of top command may not exactly match the format that is stored in the file. This is due to different kind of interpretation by the drivers(terminal driver in case when output is done on stdout).
your problem is in the system function. Read the 'man awk' carefuly and you will see that this function is exactly the same as the system C-function: it forks a new copy of Bourne shell which gets your string to interpret. So your process generates a child proces, whose standard output the father process cannot see. You get the output from the system command on your terminal, no matter how you try to redirect it. The only possibility how to get output from 'top' (and not only top but any command) to your awk script proces is as follows: CMD="top -p \"3496\" " while (CMD | getline > 0) { print $0 # do any processing of the line here } close(CMD) The same holds for all flavours of Unix. Quite simple if you know it, isn't it? I have made the same error many years ago, too.... Regards [/QUOTE] |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > help with awk script needed!!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|