I need to create a shell script to telnet to a remote server. Perform some action and then exit from that server.

I am trying with a dummy script:

telnet 8101<dummy.txt

The dummy.txt contains the password.

The script is not working with the port number. I am getting the following error:
8101: Bad file descriptor

Please advice.

password=`cat dummy.txt`
# alternatively:
telnet 8101 <<EOF
    #insert command here

Hey There,

Your results may vary depending on what's running on the port you're connected to. For instance, I don't believe straight-up telnet (port 23) allows for non-interactive here-document scripting. In such instances, you can use other programs like Perl or, probably more easily, Expect to script out a "fake human interaction"

Best wishes,


the above given solution is working

Good deal :)

Just for clarity, the point I was trying to make - try that test with port 23 - if you have telnetd running on that machine :)

I'm glad you're all set !

Best wishes,