I am trying to do telnet a Linux host inside ksh script, but the output seems to different when the same script is executed as bash script. Anyone has any Ideas ?
When the script when executed as bash
#!/bin/bash
echo -e '\x1dclose\x0d' | telnet myhost myport > /dev/null 2>&1
echo $?
output of $? is 0
Same script when executed as ksh results value of $? is 1
#!/bin/ksh
echo -e '\x1dclose\x0d' | telnet myhost myport > /dev/null 2>&1
echo $?
Any one have any ideas ?
Thanks in advance,
The return value, of
telnetis 1 if the remote host closes the connection (or any remote or network error occurs) and 0 if the local client side closes the connection successfully. My guess is, thatbashterminates the client a bit quicker thanksh, so in thekshversion, the remote host may be a bit quicker closing the session. That being said, if you put some heavy load on your client system, the version inbashmay also return a 1. The return value oftelnetis not as helpful as you might think.Also,
telnetis an interactive program that is not really suited for the use in scripts. Usencif the interaction is simple, orexpectif the interaction becomes more complex.