User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 397,616 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,414 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 1070 | Replies: 4
Reply
Join Date: Aug 2007
Posts: 26
Reputation: programmer321 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
programmer321 programmer321 is offline Offline
Light Poster

Script to telnet to another server

  #1  
Jun 25th, 2008
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.
Last edited by programmer321 : Jun 25th, 2008 at 4:15 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 39
Reputation: omrsafetyo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 8
omrsafetyo omrsafetyo is offline Offline
Light Poster

Re: Script to telnet to another server

  #2  
Jun 26th, 2008
username="myUser"
password=`cat dummy.txt`
# alternatively:
#password=$1
telnet 172.11.11.21 8101 <<EOF
    $username
    $password
    #insert command here
EOF
Reply With Quote  
Join Date: Oct 2007
Posts: 264
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: Script to telnet to another server

  #3  
Jun 27th, 2008
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
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Join Date: Jul 2008
Posts: 3
Reputation: ranam is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ranam ranam is offline Offline
Newbie Poster

Re: Script to telnet to another server

  #4  
Jul 3rd, 2008
the above given solution is working
Reply With Quote  
Join Date: Oct 2007
Posts: 264
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: Script to telnet to another server

  #5  
Jul 4th, 2008
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
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Shell Scripting Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 8:06 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC