user1336117 user1336117 - 4 months ago 15
Linux Question

Linux script to parse telnet message and exit

I am connecting to a telnet listener. Telnet server sends "1234" for every second. I want to read the message "1234" and close the telnet session. Here below is my code but it does not work.

telnet 1234
echo "Response is"$RESPONSE
echo "quit"

How can i automatically read the telnet message?


You could use internal TCP mechanism:


exec 3<>/dev/tcp/
# echo -en "eventualy send something to the server\n" >&3
RESPONSE="`cat <&3`"
echo "Response is: $RESPONSE"

Or you could use nc (netcat), but please don't use telnet!