0

Hi everyone and thank you in advance! I used to run the following script with ncat Version 5.51 and it gave me wonderful formatting

[root@server user]# for i in "cat server_list" ; do echo $i | tr '\n' '\t' ; nc -zv $i 22 ; done

host1 Connection to host1 22 port [tcp/ssh] succeeded!
host2 Connection to host2 22 port [tcp/ssh] succeeded!
host3 Connection to host3 22 port [tcp/ssh] succeeded!

But since we needed to decomm all RHEL6 servers, I'm now getting this unwanted output when running the exact same script in RHEL7 using ncat Version 7.50

[root@server2 user]# for i in "cat server_list" ; do echo $i | tr '\n' '\t' ; nc -zv $i 22 ; done

host1 Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to IP.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
host2 Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to IP.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
host3 Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to IP.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.

Is there a way to get the same formatting as how I used to get since it greatly improves readability for me? Tried redirecting left and right but no dice.
Thank you so much and any advice is appreciated!

2
  • I think your two ncs are different programs. See this answer. Commented Dec 3, 2024 at 20:37
  • Thanks for your answer Kamil! The rpm's looked similar but with different versions so did not think this was the issue Commented Dec 5, 2024 at 15:09

1 Answer 1

1

nc --verbose outputs logs to stderr, so you can capture those 2>&1, then grep to filter out the version text:

... ; nc -zv $i 22 2>&1 | grep -v Version ; ...
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.