Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Jan 2005 18:11:04 -0500
From:      Timothy Luoma <lists@tntluoma.com>
To:        jaymo@cromagnon.cullmail.com
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: running interactive program from shell script
Message-ID:  <dce54c84eb6186457fcbe553b3491393@tntluoma.com>
In-Reply-To: <200501300533.51350.jaymo@cromagnon.cullmail.com>
References:  <200501300533.51350.jaymo@cromagnon.cullmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On Jan 30, 2005, at 6:33 AM, Jay Moore wrote:

> I need a shell script that initiates a telnet session to another host.
>
> I have come up with the following, but unfortunately it terminates 
> when the script
> is finished. What I wanted was for the telnet session to remain 
> "alive" and
> interactive until manually terminated.
>
> Is there a way to accomplish this in a shell script?

Well, you'll have to give a little more information about what you're 
trying to do, because "initiating a telnet session" to me means 
"starting telnet" but it looks (if I am correctly interpreting/guessing 
what you are trying to do below) like you are trying to create a shell 
script which will start a telnet session AND automatically log you in.

> I've been told that I'll have to use "expect" or similar to accomplish 
> this,
> but it seems to me that I should be able to do this using just Bourne 
> shell
> commands.

Yes, if you want to automatically log yourself in via telnet, then you 
will need expect.  There's no way to do this via /bin/sh

> #! /bin/sh
>
>     (sleep 3;
>     echo "password";
>     sleep 3;
>     echo "ls -la";
>     sleep 3;
>     ) | telnet -l user 192.168.0.2

Ok, so this says: "Wait 3 seconds, echo 'password' to stdout, wait 3 
seconds, then show the output of 'ls -la' then wait 3 seconds and then 
send the output to telnet [which will, as far as I know, completely 
ignore everything you send to it] and then telnet to 192.168.0.2 as 
user 'user'

3 options

a)  If you really want to do this, you'll need 'expect'

b) Now if this is just across your private network, you may not be 
overly concerned with security, HOWEVER I would highly recommend using 
ssh instead.  Not only is it more secure, but it is MUCH easier to 
setup passwordless ssh.

c) If you don't want to go with ssh and want to be really insecure, 
checkout rsh and hosts.equiv [shudders with the fear of anyone actually 
being that trusting in this day & age]

TjL



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?dce54c84eb6186457fcbe553b3491393>