Netstat AND rmsock

Hi,
Is there a way to execute these two commandes on one line?:

netstat -Aan | grep LISTEN |awk '{ print $1}'

And give the output as parameter to rmsock tcpcb

Something like:

netstat -Aan | grep LISTEN |awk '{ print $1}' | rmsock tcpcb

Thanks.

I don't know the specifics of rmsock and/or if the order of parameters/switches matter - you'll have to adjust

rmsock tcpcb "$(netstat -Aan | awk '/LISTEN/{ print $1}' )"

1 Like

Thanks.
I received:
usage: rmsock Addr TypeOfAddr

Regards.

given the usage message you got, how do you think you need to adjust the command?

In your other case, you can try the long shell command in the given URL.
The following is an attempt to shorten the command:

netstat -Aan | grep -w LISTEN | while read sockaddr protocol x x port x; do set -- $(rmsock "$sockaddr" tcpcb | grep socket); test -n "$9" && ps -ef | grep -w "$9"; echo "$port"; done

If it does not work, then turn debug mode on with

set -x

and reply with the result.

2 Likes

may be:

rmsock "$(netstat -Aan | awk '/LISTEN/{ print $1}' )" tcpcb
The socket 0xf1000e00143a2808 is being held by proccess 10747994 (sshd).

Then it returns only one row. It escapes the others.
Regards.

maybe (if rmsoxk doesn'take multiple addresses?)

while addr in "$(netstat -Aan | awk '/LISTEN/{ print $1}' )"
do
   rmsock "${addr}" tcpcb
done
1 Like

Thank you.
while addr in "$(netstat -Aan | awk '/LISTEN/{ print $1}' )"

do
rmsock "${addr}" tcpcb
done
ksh: addr: not found.

Sorry, not while but for

Thanks.
for addr in "$(netstat -Aan | awk '/LISTEN/{ print $1}' )"

do
rmsock "${addr}" tcpcb
done
The socket 0xf1000e00143a2808 is being held by proccess 10747994 (sshd).

Again just one row.
Regards.

then netstat -Aan | awk '/LISTEN/{ print $1}' return just ONE value.
add set -x to the top of your script to enable debugging.

Sorry, - remove " around $(netstat -Aan | awk '/LISTEN/{ print $1}' )
My bad....

Thank yuo.

for addr in $(netstat -Aan | awk '/LISTEN/{ print $1}' )
do
rmsock "${addr}" tcpcb
done

Worked fine.

Regards.
PS for webmaster.
This black background is HORRIBLE.

1 Like

2 posts were split to a new topic: Thoughts on the Default Dark Theme for the Site