From owner-freebsd-questions@FreeBSD.ORG Mon Jan 31 04:24:37 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 D4C2716A4CE for ; Mon, 31 Jan 2005 04:24:37 +0000 (GMT) Received: from cromagnon.cullmail.com (cromagnon.cullmail.com [67.33.58.202]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4130A43D31 for ; Mon, 31 Jan 2005 04:24:37 +0000 (GMT) (envelope-from jamoore@cromagnon.cullmail.com) Received: from cromagnon.cullmail.com (localhost.cullmail.com [127.0.0.1]) j0V4N1xY010597; Sun, 30 Jan 2005 22:23:01 -0600 (CST) (envelope-from jamoore@cromagnon.cullmail.com) Received: from localhost (localhost [[UNIX: localhost]]) by cromagnon.cullmail.com (8.12.10/8.12.10/Submit) id j0V4N1oP010596; Sun, 30 Jan 2005 22:23:01 -0600 (CST) (envelope-from jamoore) From: Jay Moore To: Timothy Luoma Date: Sun, 30 Jan 2005 22:23:00 -0600 User-Agent: KMail/1.6.1 References: <200501300533.51350.jaymo@cromagnon.cullmail.com> In-Reply-To: MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200501302223.00779.jaymo@cromagnon.cullmail.com> 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 Reply-To: jaymo@cromagnon.cullmail.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 04:24:38 -0000 On Sunday 30 January 2005 05:11 pm, Timothy Luoma 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. Precisely... > > 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 A-a-a-r-r-r-g-h-h. You are correct! But what I still don't understand is why I can start and maintain a telnet session from a shell script, but if I add a couple of lines to send the password the damn thing terminates. In other words: #! /bin/sh telnet -l user 192.168.0.2 will start an "interactive" telnet session which will run until I enter 'exit'. BUT - if I embellish it just a bit (as in the script below) to echo the password and ls -la the remote directory it exits as soon as the script finishes. As the bank robber in 'Dirty Harry' said, "I gots to know." As for what I'm trying to do: I have a requirement to administer a number of remotely located embedded devices; these devices do not support ssh - only telnet. To avoid the obvious security issues, I am going to co-locate a "real" computer at each remote location. I will ssh into the "real" computer, and then telnet over a local network to the embedded device(s). I realize there are many ways of accomplishing this, but I'm kind of hung up on doing it "my way" :) > > > #! /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' No - not exactly. You have the sequence correct, but the results are that the password is sent to the remote telnet host, it does log me in, it performs the ls -la (displaying the result on my local console), and then exits! Puzzledly, Jay