Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Running script with telnet

40 views
Skip to first unread message

Matheus Cunha Torres

unread,
Mar 20, 2000, 3:00:00 AM3/20/00
to
Is it possible to telnet another box and run a script from your machine
in the foreign host. As an example, suppose I want to telnet a pop
server
(telnet foreign.domain.com 110) and automatically delete the messages
there and log out. It's just an example, I know there are pop reader
that
can do that...

Is ther any option in telnet that allows me executing the comands after
conecting?


Ryan Hatch

unread,
Mar 20, 2000, 3:00:00 AM3/20/00
to
Yes, use remsh. Man pages should give you the details.

Tim Hockin

unread,
Mar 20, 2000, 3:00:00 AM3/20/00
to
In comp.os.linux.misc Matheus Cunha Torres <te...@newview.com.br> wrote:
: Is it possible to telnet another box and run a script from your machine
: in the foreign host. As an example, suppose I want to telnet a pop
: server
: (telnet foreign.domain.com 110) and automatically delete the messages
: there and log out. It's just an example, I know there are pop reader
: that
: can do that...

: Is ther any option in telnet that allows me executing the comands after
: conecting?

man rsh
man expect

--
Tim Hockin
tho...@ais.net
tho...@isunix.it.ilstu.edu
This program has been brought to you by the language C and the number F.

Frank da Cruz

unread,
Mar 20, 2000, 3:00:00 AM3/20/00
to
In article <38D65A06...@newview.com.br>,

Matheus Cunha Torres <te...@newview.com.br> wrote:
: Is it possible to telnet another box and run a script from your machine in
: the foreign host. As an example, suppose I want to telnet a pop server
: (telnet foreign.domain.com 110) and automatically delete the messages there
: and log out. It's just an example, I know there are pop reader that can do
: that...
:
: Is ther any option in telnet that allows me executing the comands after
: conecting?
:
A very common question, and one which always bring forth a blizzard of
different answers, the most common one being "use expect". Here's another
perspective, quoting myself from a recent comp.unix.programmer thread:

From: f...@watsun.cc.columbia.edu (Frank da Cruz)
Newsgroups: comp.unix.programmer
Subject: Re: Telnet
Date: 10 Mar 2000 23:45:27 GMT
Organization: Columbia University
Lines: 75

In article <38C94BFB...@gcg.com>, Chuck Dillon <dil...@gcg.com> wrote:
: ...
: Another poster already mention this but since you don't know
: perl now C I'm guessing a vague reference to 'expect' might
: not stick in your mind.
:
: Expect is a scripting tool that is designed to automated command
: line interactions via pseudo-terminals. It should be exactly
: what you are looking for. Take a look at http://expect.nist.gov.
:
Expect will normally do the job, but it's not available for as many
UNIX platforms as C-Kermit, let alone non-UNIX platforms like VMS,
OS-9, VOS, etc.

Also there is an intrinsic weakness in the 'expect' approach -- all
that 'expect' sees is text. So when automating interactions with some
other program such as telnet or ftp, the only way to tell whether a
particular command succeeded or failed is by parsing the response --
which is notoriously unreliable. In the case of Telnet, it has no
way of knowing if the text it's looking at is from the remote host
or from the local Telnet program. It's just a stream of text.

When the scripting language is intrinsic to the Telnet client, it
knows when a command succeeds or fails because it executed the command
itself. When using 'expect' to drive the Telnet program, you have
to account for various responses:

$ telnet foo.blah <-- Bad hostname
foo.blah: unknown host
telnet>

$ telnet pc.xyzcorp.com <-- Host with no telnet server
Trying 123.123.123.123
telnet: connect: Connection refused
telnet>

$ telnet down.xyzcorp.com <-- Host is down
Trying 123.123.123.124 ...
telnet: connect: Connection timed out
telnet>

$ telnet mainframe.xyzcorp.com <-- Incompatible telnet server
Trying 123.123.123.125 ...
Connected to mainframe.xyzcorp.com
Escape character is '^]'.
Connection closed by foreign host.

$ telnet okhost.com <-- This one worked
Welcome to okhost.com, blah blah ...
login:

And so on...

In C-Kermit, this is programmed as follows:

set host <hostname> /telnet
if fail (take-desired-action) <-- It doesn't matter what the message is.
input 10 login:
if fail ...

Once the connection is made, of course, you still have to script the remote
prompts, commands, and responses. Unless, of course, a Kermit server is
available on the remote system, in which case you can use client/server
commands for most common tasks (including file transfer) and skip the
scripting altogether.

C-Kermit is at:

http://www.columbia.edu/kermit/ckermit.html

Sample telnet and other scripts are at:

http://www.columbia.edu/kermit/ckscripts.html

- Frank

(end quote)

0 new messages