From owner-freebsd-questions@FreeBSD.ORG Sun Jan 30 23:11:10 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 92B9C16A4CF for ; Sun, 30 Jan 2005 23:11:10 +0000 (GMT) Received: from whisk.dreamhost.com (whisk.dreamhost.com [205.196.208.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6529243D46 for ; Sun, 30 Jan 2005 23:11:10 +0000 (GMT) (envelope-from lists@tntluoma.com) Received: from [192.168.2.2] (adsl-68-252-33-50.dsl.wotnoh.ameritech.net [68.252.33.50]) by whisk.dreamhost.com (Postfix) with ESMTP id 199AC17510D; Sun, 30 Jan 2005 15:11:08 -0800 (PST) In-Reply-To: <200501300533.51350.jaymo@cromagnon.cullmail.com> References: <200501300533.51350.jaymo@cromagnon.cullmail.com> Mime-Version: 1.0 (Apple Message framework v619.2) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Timothy Luoma Date: Sun, 30 Jan 2005 18:11:04 -0500 To: jaymo@cromagnon.cullmail.com X-Mailer: Apple Mail (2.619.2) cc: FreeBSD Mailing List Subject: Re: running interactive program from shell script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Jan 2005 23:11:10 -0000 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