Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

telnet scripting assistance 1

Status
Not open for further replies.

fgg123

IS-IT--Management
Mar 7, 2003
6
US
Scenario:

1. Logged into a host UNIX (System A).
2. Telneting to a switch (1.2.3.4) that requires a
login/password for access. (telnet is the only method
allowed to enter switch)
3. Running a display command (e.g.: display 123/S 23/A 14)
to capture data back to a file on host UNIX (System A).

Trying to use a here document on System A as follows:

#####################################################
get-switch-data.sh

telnet 1.2.3.4 <<-EOF 2>&1 > /home/switch/sw-data/log-data
guest
guest
display 123/S 23/A 14
EOF

#####################################################

Trouble I'm running into, is with the login/password
required. How can I pass it(login/password) to telnet (I know about the -l login) option on command line telnet -l guest, but no password option), and get my log-data from the command being passed.

Anny help, Thanks!


FGG123

 
For this I usually use expect as shell telnet within scripts has been flakey for meself.

#!/usr/bin/expect --

spawn /usr/bin/telnet
expect &quot;telnet>&quot;
send &quot;open YOUR_IP_HERE\r&quot;
expect &quot;ogin&quot; # In case login is &quot;Login or login&quot;
send &quot;YOUR_LOGIN_HERE\r&quot;
expect &quot;ssword&quot; # In case password is &quot;Password or password&quot;
send &quot;YOUR_PW_HERE\r&quot;
expect &quot;SOME_PROMPT (I.E. $>)&quot;
send &quot;YOUR_COMMANDS_HERE\r&quot;
expect &quot;SOME_PROMPT (I.E. $>)&quot;
send &quot;exit\r&quot;
expect eof


To log, just run script name > log 2>&1. If you do not have the expect binary installed, go to:
 
You cannot use the shell to do this.
Use pmcmicha's advice and look at expect.

His script will not work as is, but serves
as a model.
Repost to the tcl group if you need more help.
 
Thank you very much for your help/support!
This worked perfectly for what I was trying to implement.!
Many thanks!
Regards,
FGG123
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top