1848620 Members
1932 Online
104033 Solutions
New Discussion

Re: telnet automatically

 
Romeo_Lou
Advisor

telnet automatically

How can i use telnet automatically, for other word, I want to telnet to another unix and I can use the user and password that predefine in script.
B^R
7 REPLIES 7
U.SivaKumar_2
Honored Contributor

Re: telnet automatically

Hi,
Create a script mytelnet.sh with below contents

#!/opt/local/bin/bash
(echo "testuser";\
echo "test123";\) | telnet x.x.x.x

Where x.x.x.x is the Ip address of the remote server.

regards,
U.SivaKumar



Innovations are made when conventions are broken
U.SivaKumar_2
Honored Contributor

Re: telnet automatically

Hi,
Create a script mytelnet.sh with below contents

#!/usr/bin/sh
(echo "testuser";\
echo "test123";\) | telnet x.x.x.x

Where x.x.x.x is the Ip address of the remote server.

regards,
U.SivaKumar



Innovations are made when conventions are broken
T G Manikandan
Honored Contributor

Re: telnet automatically

#!/bin/sh
(sleep 5
echo
sleep 5
echo
sleep 5
echo ls
sleep 5
echo exit) |telnet hostname

check this link
Clay has a perl script for telnet

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x62777d4cf554d611abdb0090277a778c,00.html


Thanks
John Meissner
Esteemed Contributor

Re: telnet automatically

download and install a program called expect (included is autoexpect). after you download and install...
type autoexpect -f filename telnet servername

you will go through the login process and when you're done hit the to stop. This will write a script for you (filename) - edit this file and remove some extra characters durring the login process. I'm attaching an autoexpect script for you to use as an example.
All paths lead to destiny
A. Clay Stephenson
Acclaimed Contributor

Re: telnet automatically

My method would be to use the Net::Telnet Perl module. You get user-selectable timeouts AND error-checking for free.

It can be as trivial as this (adapted from the man pages):

use Net::Telnet ();

my $passwd = "topsecret";
my $username = "cstephen";

$t = new Net::Telnet (Timeout => 15,
Prompt => '/bash\$ $/');
$t->open("sparky");
$t->login($username, $passwd);
@lines = $t->cmd("/usr/bin/who");
print @lines;


You can download the Net::Telnet module from www.perl.org/CPAN. It's really hard to beat the simplicity of this method especially when you would also like to automatically add error checking.

If it ain't broke, I can fix that.
Ken Hubnik_2
Honored Contributor

Re: telnet automatically

Another consideration is using rlogin.
John Meissner
Esteemed Contributor

Re: telnet automatically

aren't the 'r' services a security hole though?
All paths lead to destiny