Quitting Telnet Properly in Scripts
June 08, 2011 - 12:00 pm
Extremely useful if you want to be able to differentiate exit status to determine if a connection was attempted or not:
(echo 'ESC' | tr 'ESC' '\035' ; echo "quit") | telnet 127.0.0.1
This connects, then sends the default ctrl+] followed by quit, which will exit normally with a status of 0. If you're connecting to a remote system, it may be helpful to toss in a call to sleep. EG:
(sleep 5; echo 'ESC' | tr 'ESC' '\035' ; echo "quit") | telnet 192.168.254.42