Operating System - HP-UX
1752537 Members
4783 Online
108788 Solutions
New Discussion юеВ

How to write script for telnet session

 
Edward Tse
Occasional Contributor

How to write script for telnet session

Dear all,

I want to write a script ( .sh ) for telnet session and auto login to the system. How to do it ? Please help
11 REPLIES 11
KapilRaj
Honored Contributor

Re: How to write script for telnet session

search in this forum buddy ... this has been already discussed here

Kaps
Nothing is impossible
Sanjay Kumar Suri
Honored Contributor

Re: How to write script for telnet session

Check this thread:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=496072

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Manish Srivastava
Trusted Contributor

Re: How to write script for telnet session

Fabio Ettore
Honored Contributor

Re: How to write script for telnet session

Hi,

check this thread:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=496072

Anyway this was posted more times in ITRC forum, try to insert keywords 'telnet script' in ITRC search.

Best regards,
Ettore
WISH? IMPROVEMENT!
Edward Tse
Occasional Contributor

Re: How to write script for telnet session

It is right?

Script:

Telnet ip-address
sleep 5
echo username
sleep 5
echo password

I try this, but it isn't work. Please help
Nicolas Dumeige
Esteemed Contributor

Re: How to write script for telnet session

There a way to do it this way, check http://steve-parker.org/sh/expect.shtml

But, you'll find that Expect is really what you need, if rsh (or ssh) won't be satisfactory (why ??).

Ant (what make is for C, ant is for Java) has also telnet scripting capabilities).

Cheers

Nicolas
All different, all Unix
Rodney Hills
Honored Contributor

Re: How to write script for telnet session

If you are familiar with "perl", you can drive a telnet session with "Net::Telnet" module. Example-

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

HTH

-- Rod Hills
There be dragons...
rmueller58
Valued Contributor

Re: How to write script for telnet session

Install EXPECT

Download HERE:
http://hpux.cs.utah.edu/hppd/hpux/Tcl/expect-5.41/


#!/usr/bin/expect
spawn telnet
expect "login"
send "USERNAME\r"
expect "Password:"
send "PASSWORD\r"
expect "# "

YOU CAN SEND and Expect commands..

Get the OReilly Book "Expect"

rmueller58
Valued Contributor

Re: How to write script for telnet session

Here is the Expect Main Site
http://expect.nist.gov/