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.
#!/bin/bash
telnet 192.168.10.24 1234
read $RESPONSE
echo "Response is"$RESPONSE
echo "quit"
How can i automatically read the telnet message?
You could use internal TCP mechanism:
#!/bin/bash
exec 3<>/dev/tcp/127.0.0.1/80
# 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!