0

From the following nc command,i would like to redirect source-server.fqdn name to the output file. By default nc command is not returning the source-server.fqdn in the output.

nc -zv -s source-server.fqdn dest-server.fqdn 1234 >> file.txt 2>&1
3
  • 3
    What stops you from using echo source-server.fqdn >file.txt before running your nc command? Commented Feb 14, 2024 at 9:50
  • 2
    Does this answer your question? How can I save the command and its execution output to file at the same time Commented Feb 14, 2024 at 9:58
  • @Kusalananda Or something like { echo source-server.fqdn; nc -zv -s ...; } >>file.txt Commented Feb 14, 2024 at 10:57

1 Answer 1

0

nc command does not provide the source server's fully qualified domain name (FQDN) in its output.-s option in nc is used to specify the source IP address, not FQDN.

if you want to include the source server's FQDN in the output, you would need to use a different command. for example, you could use nslookup to get the FQDN of the source server and then use echo to include it in the output. Here's an example:

echo "Source server FQDN: $(nslookup source-server-ip | grep name | awk '{print $4}')" | tee -a file.txt
nc -zv -s source-server-ip dest-server.fqdn 1234 >> file.txt 2>&1

here, nslookup source-server-ip | grep name | awk '{print $4}' is used to get the FQDN of the source server. tee -a file.txt command is used to append the output to the file.

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.