telnet in a script | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

telnet in a script

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-15-2000
vaccari vaccari is offline
Registered User
 
Join Date: Dec 2000
Last Activity: 18 December 2000, 11:05 AM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Question

I'm need to connect to another host in a script using the telnet command. How do I pass the login and password to be able to connect to the other host from within the script?
Sponsored Links
    #2  
Old 12-15-2000
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 29 July 2014, 8:48 AM EDT
Location: Asia pacific region
Posts: 13,003
Thanks: 515
Thanked 868 Times in 397 Posts
When you open a telnet session in a script you must read the session prompts and write the replies. For example, you open a telnet session in a script and read the session and when you match the word 'Login' (or whatever) you write the user id. The same for password.

In other words, you automate in the script what you manually do at the keyboard. When you do it from the keyboard, you telnet, then wait for the login prompt. When you get the login prompt, you type the login. etc.

Writing a script is the same for telnet sessions, however instead of the keyboard, you echo (or write) in the script. Instead of seeing the login problem, you match the pattern in the script (your eyes, so to speak).
Sponsored Links
    #3  
Old 12-15-2000
vaccari vaccari is offline
Registered User
 
Join Date: Dec 2000
Last Activity: 18 December 2000, 11:05 AM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
I understand the concept very well. I have tried to automate it in my script but it doesn't take the login and password. Do you have an example?
    #4  
Old 12-15-2000
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 29 July 2014, 8:48 AM EDT
Location: Asia pacific region
Posts: 13,003
Thanks: 515
Thanked 868 Times in 397 Posts
I don't have an example handy, but as I recall the working construct is based on this form of code fragment:


Code:
while {

#put conditional logic here

} telnet 111.222.333.444


I once wrote a script that automatically 'telnetted' into hundreds of Cisco routers and changed the passwords when an employee was terminated. This was about 7 years ago and my memory on the actual code is foggy. I do remember that we used KSH and used a contruct like the one above.

I suggest you get out your best shell programming book and use the construct above in the correct syntax. For example, I don't recall if you use a pipe "|" or perhaps a "<" redirection tag to send the telnet output to the while logic block. You would have to get this from studying the construct and perhaps some simple trial and error. Sorry not to remember more.

When you get it right, please post.






Sponsored Links
    #5  
Old 12-15-2000
vaccari vaccari is offline
Registered User
 
Join Date: Dec 2000
Last Activity: 18 December 2000, 11:05 AM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Neo, I'm also trying to telnet into hundreds of routers, which is why I need the telnet command (because of port 23) When I get it right I will post it.

Sponsored Links
    #6  
Old 12-15-2000
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 29 July 2014, 8:48 AM EDT
Location: Asia pacific region
Posts: 13,003
Thanks: 515
Thanked 868 Times in 397 Posts
Great. When you get it working for TELNET, the same idea will work for SSH. If you are using Cisco, they now support SSH. As PxT points out, this might be a good future revision if you require a more secure solution.

Telnet is a good first step. Cisco has SSH built into the recent IOS releases.
Sponsored Links
    #7  
Old 12-18-2000
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
 
Join Date: Oct 2000
Last Activity: 7 May 2009, 12:22 PM EDT
Location: Sacramento, CA
Posts: 909
Thanks: 0
Thanked 4 Times in 4 Posts
You can use a pipe to send the output to telnet. Something like:

Code:
#!/bin/ksh
( echo open hostname
  sleep 5
  echo username
  sleep 1
  echo password
  sleep 1
  echo some more output, etc. ) | telnet

Combine with a while loop or however you want to do it...

HTH
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Telnet script Pouchie1 Shell Programming and Scripting 3 08-27-2010 06:08 AM
Telnet and ssh in a script marwan UNIX for Dummies Questions & Answers 3 06-11-2007 10:58 AM
Telnet in a script insania Shell Programming and Scripting 5 04-15-2007 01:32 PM
telnet through script arun.viswanath UNIX for Dummies Questions & Answers 1 03-26-2006 11:33 AM
ksh telnet script rwunwla Shell Programming and Scripting 5 12-16-2005 08:22 AM



All times are GMT -4. The time now is 10:47 AM.