Skip to main content
3 of 5
typo
Stéphane Chazelas
  • 585k
  • 96
  • 1.1k
  • 1.7k

timeout command and pipe - order of precedence

I need to test receipt of TCP data. I may not use iperf.

The requirements are saying that I should create a TCP server and someone will send random data. I need to count the number of bytes received.

I have been told to use the following:

timeout 60 cat < /dev/tcp/IP_addr/port | wc –c > byte_count-n.txt

Will this do what they think it will? Will it receive data for 60 seconds and then, when the timeout expires, pipe the received data to wc, which will write the total to a disk file?

As a programmer, I would feel happier if it read

(timeout 60 cat < /dev/tcp/IP_addr/port) | wc –c > byte_count-n.txt

But obviously the shell won’t accept that. Am I correct to be worried?

Note that we are using the Ash shell, but there is some concern that only Bash supports /dev/tcp

Mawg
  • 313
  • 5
  • 15