|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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.444I 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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
||||
|
||||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|