I am connecting to a telnet listener. Telnet server sends some data for every second. I want to read the messages while X seconds and write it into a file (we'll take 6 seconds for the example).
Note: The IP address has been changed to 'IP' for the example. Same for 'Port'.
I already tried some things:
#!/bin/bash
#myScript.sh
telnet IP Port >> myFile.txt
sleep 6
pkill myScript.sh
This solution write in my file but my script never ends.
Here my 2nd proposition:
#!/bin/bash
#myScript.sh
timeout 6 telnet IP Port >> myFile.txt
Here, it's another issue, timeout is respected, the script ends after 6 seconds but in 'myFile.txt', I have
Trying IP...
Connected to IP.
Escape character is '^]'
How can I make this script right?
Note: I must use Telnet.