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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Telnet Script

Status
Not open for further replies.

ddankani

Technical User
Jul 9, 2002
5
US
Being a novice, can someone tell me how to input a user name Via a script once a device returns a login prompt for a telnet session? I'd like to automate logining in (telnet) save files, logout.
 
If you're just saving files, you would be better off using FTP. Is there a reason you're not?
 
Or you can look into the r commands: rsh, rcp, rlogin, .rhosts. They aren't very secure, but if that isn't an issue, they are wonderful for scripting. Do a man on rsh or rcp to get the full story. Einstein47
(How come we never see the headline, "Psychic Wins Lottery"?)
 
ddankani:

I'm assuming your comment above is in reply to Einstein's description of the "r" commands. I must repectfully disagree with you. Every unix flavor I've seen from SCO Xenix to Linux has the "r" commands.

I'd be interested in knowing which unix variant doesn't have them.

Regards,

Ed
 
I guess I'm confussing everyone. I manage a network with HP OV and would like to automate the saving of files to non unix based devices that support telnet. I need to have the script respond to the login prompt and then I guess I can go from there.
 
Why not use ssh ? it's more secure than telnet and you can setup a user to have Public-Keys allowing direct login with no pass-phrase (you should be carefull to protect your "private key" though)

If you have ssh then as the username (first on one server) do:
ssh_keygen –t rsa
NOTE: just enter a <CR> at the prompt for pass-phrase, this will allow non-interactive login.

Then the copy contents of username/.ssh/id_rsa.pub and appended them to a file called username/.ssh/authorized_keys2 on the second server, (this file must then be chmod’ed 600 to make it secure).

This process can then be repeted on the second server (appending the contents of username/.ssh/id_rsa.pub from server two into username/.ssh/authorized_keys2 on server one)


I hope this helps.
 
You may need something like &quot;expect&quot; to do this sort of thing.

I haven't used it myself but I think it's part of TCL.
 
You guys are all pretty smart, but I think your missing the trees for the forest. I have one, exactly one unix box not two! Is what I want to do possible? Does the fact that the telnet session starts within the script mean I can't have the script pass the user name and password?
 
the problem that everyone is trying to address is the correct one, programs like telnet do not allow a script to directly &quot;feed&quot; data to them. You need something like expect or Perl::Net::Telnet to achieve this. Mike
________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Thanks Mike and Wardy66 thats what I was trying to find out. Would you have the time to give me an example of how to use Expect to accomplish what I need to do? As for Chapter11, I'm telneting into the device and asking it to save files locally to flash and also a pcmcia card.
 
Sorry, I've got no idea how to actually do it [bigears]

I believe the Perl module Net::Telnet that may be able to help. I haven't used it either but I started investigating it for the possible use of file transfers over secured networks (between UNIX hosts with NFS/rsh/FTP disabled).

If you wish to use Perl, you could issue a

$ perldoc Net::Telnet

command to read the doco. Here's an example from that
Code:
use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,
                      Prompt => '/bash\$ $/');
$t->open(&quot;sparky&quot;);
$t->login($username, $passwd);
@lines = $t->cmd(&quot;/usr/bin/who&quot;);
print @lines;

As I said, I've got no concrete experience unfortunately.
 
Hi ddankani,

This is the way to automate telnets using the 'EXPECT'.

--------------------------------------------------------
#! /usr/misc/bin/expect --
spawn telnet eros17 ----->server name
expect &quot;login:&quot;
send scadm ------>user name
expect &quot;Password:&quot;
send scadm ------->password
expect &quot;eros17*&quot;
interact
-------------------------------------------------------
regards,
Priya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top