Hello,

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:
#!/bin/bash

telnet 172.11.11.21 8101<dummy.txt
exit

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.

username="myUser"
password=`cat dummy.txt`
# alternatively:
#password=$1
telnet 172.11.11.21 8101 <<EOF
    $username
    $password
    #insert command here
EOF

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,

Mike

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,

Mike