Referencing this question: automating telnet session using bash scripts
I am trying to capture the time it takes for a remote host to timeout.
Let's say it's 10 seconds.
By hand, I can launch time telnet host port
input some commands and then do nothing and after 10 seconds time
's output will hold my needed time.
While, in a script, the issue is that using this solution:
{ echo "command"; } | time telnet host port
when the pipes end, it sends an EOF and telnet closes immediately. I can solve this by adding a sleep n
as my last piped command, but then everything hangs for that timeout (which can be more than the actual server timeout).
Just to explain what I'm trying to do let's borrow Google's help. I want my time output to be 5 minutes, which is what Google seems to use as timeout. Instead:
{ echo "GET / HTTP/1.1"; echo "Host: www.google.com"; echo "Connection: keep-Alive"; echo ""; echo ""; } | time telnet www.google.com 80 2>&1
Gives 0
- wrong (EOF is sent immediately)
{ echo "GET / HTTP/1.1"; echo "Host: www.google.com"; echo "Connection: keep-Alive"; echo ""; echo ""; sleep 10; } | time telnet www.google.com 80 2>&1
Gives 10
- wrong
{ echo "GET / HTTP/1.1"; echo "Host: www.google.com"; echo "Connection: keep-Alive"; echo ""; echo ""; sleep 1; } | time telnet www.google.com 80 2>&1
Gives 1
- wrong
{ echo "GET / HTTP/1.1"; echo "Host: www.google.com"; echo "Connection: keep-Alive"; echo ""; echo ""; sleep 900; } | time telnet www.google.com 80 2>&1
Gives 900
- wrong (here I would expect the telnet to stop given the remote host sends a kill, but instead the sleep wins)
So, how can I solve this? Thanks!