1844882 Members
3261 Online
110233 Solutions
New Discussion

Re: awk scripting

 
SOLVED
Go to solution
Joshua Scott
Honored Contributor

awk scripting

i'm gathering the tcp info and possible differences on our 7 servers, so I used this command to gather a list of parameters:

ndd -h sup | grep tcp_ | awk '{print $1}' > ndd.input

which gave me a list of all supported tunables in ndd.input

I then want to run a script that puts the tunable name followed by a space, then the parameter setting like this:

...
tcp_xmit_lowater_lnf 16384
tcp_xmit_lowater_lnp 2048
...

so i can diff them.
I can use this command:
ndd -get /dev/tcp tcp_xmit_lowater_lnf
to get:
16384

here's the script I have:
awk '{print "echo " $0 "\nndd -get /dev/tcp " $0}' ndd.input | sh > ndd.out.$HOST

however, this outputs this form:
tcp_xmit_lowater_lnf
16384
tcp_xmit_lowater_lnp
2048

so when I diff them, it shows the difference in values, but not which parameters they are.

Any Ideas?
Thanks!
Josh
What are the chances...
4 REPLIES 4
David Child_1
Honored Contributor

Re: awk scripting

I'm still looking at how to do it strictly in awk, but you could use this:

for p in `< ndd.input`
do
echo "$p \c"
ndd -get /dev/tcp $p
done

David
David Child_1
Honored Contributor
Solution

Re: awk scripting

Sorry, ignore that last one. It would work, but here is the awk answer:

awk '{print "echo \""$0 " \c\" ;ndd -get /dev/tcp " $0}' ndd.input | sh

David
c_51
Trusted Contributor

Re: awk scripting

try something like this:

ndd -h sup | awk '/tcp_/ {
a="ndd -get /dev/tcp "$1 | getline value;
print $1, value;
}' > ndd.out.$HOST
Joshua Scott
Honored Contributor

Re: awk scripting

Thanks, Exactly what I was looking for.

Josh
What are the chances...