running interactive program from shell script
lists at tntluoma.com
Sun Jan 30 15:11:10 PST 2005
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
> but it seems to me that I should be able to do this using just Bourne
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
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]
More information about the freebsd-questions