From owner-freebsd-questions@FreeBSD.ORG Fri Nov 1 06:48:24 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B608D942 for ; Fri, 1 Nov 2013 06:48:24 +0000 (UTC) (envelope-from matthew@FreeBSD.org) Received: from smtp.infracaninophile.co.uk (smtp6.infracaninophile.co.uk [IPv6:2001:8b0:151:1:3cd3:cd67:fafa:3d78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5B3372278 for ; Fri, 1 Nov 2013 06:48:24 +0000 (UTC) Received: from seedling.black-earth.co.uk (seedling.black-earth.co.uk [81.2.117.99]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.14.7/8.14.7) with ESMTP id rA16mJM4028993 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Fri, 1 Nov 2013 06:48:19 GMT (envelope-from matthew@FreeBSD.org) DKIM-Filter: OpenDKIM Filter v2.8.3 smtp.infracaninophile.co.uk rA16mJM4028993 Authentication-Results: smtp.infracaninophile.co.uk/rA16mJM4028993; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy) Message-ID: <52734EB2.9010207@FreeBSD.org> Date: Fri, 01 Nov 2013 06:48:18 +0000 From: Matthew Seaman User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: freebsd-questions@freebsd.org Subject: Re: Inputs and outputs in the right order References: <201311010256.rA12u1jx009134@x.it.okstate.edu> In-Reply-To: <201311010256.rA12u1jx009134@x.it.okstate.edu> X-Enigmail-Version: 1.6 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="9IsjK8UeB7xXCH2NIowIQ4nQSqeMVADVk" X-Virus-Scanned: clamav-milter 0.97.8 at lucid-nonsense.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on lucid-nonsense.infracaninophile.co.uk X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Nov 2013 06:48:24 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --9IsjK8UeB7xXCH2NIowIQ4nQSqeMVADVk Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 01/11/2013 02:56, Martin McCormick wrote: > One of the beauties of unix is the ability to open a > shell such as omshell or even the Bourne or C shells and feed > commands to the shell from a script. One can capture the output > of the shell to generate log entries or status messages for the > benefit of the operator of the application. >=20 > If you do that, however, there is an interesting > problem. If one was to manually enter commands to the shell, the > output looks like: >=20 > some_command > shell_output for one or more lines and then > some_other_command > shell_response. >=20 > When an automated script is entering commands, what > appears to happen is that standard input sucks in gobs of lines > as fast as it can and then the shell runs them sequentially if > possible so it all happens very fast on a modern system. >=20 > The problem is that if one is capturing the session, the > shell usually doesn't echo each command as executed. If you use > a special application such as script, one sees all the commands > fed in as a block followed by the results of the sequential > execution of the block of commands coming out as a block. It is > sometimes hard to tell exactly what happened to make the job > fail because one does not have the command string followed by > the results. >=20 > I know that expect does a great job of logging a session > but I am wondering if there is an easier way to get the shell > input echoed interwoven with all the output. In shorter words, > what is the easiest way to produce a session log that reads like > what actually happened when it happened? >=20 > Thanks for any and all constructive ideas. When a process -- any process, which includes shells -- is reading from a tty, then the input is set to line bufferred. The reading process see a chunk of input as soon as you hit return. However, when the input comes from a pipe or just by reading a file, then the input is set to block buffered, so a chunk of text 4kB in size is read each time. Now, with most programming languages you can control the buffering of their input (eg. perl has the '$|' variable). As far as I can see, there isn't a way to do that from *within* a shell script, but you can force the shell to behave interactively by invoking it as '/bin/sh -i' Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. PGP: http://www.infracaninophile.co.uk/pgpkey --9IsjK8UeB7xXCH2NIowIQ4nQSqeMVADVk Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.20 (Darwin) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQJ8BAEBCgBmBQJSc06yXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQ2NTNBNjhCOTEzQTRFNkNGM0UxRTEzMjZC QjIzQUY1MThFMUE0MDEzAAoJELsjr1GOGkATvNoP/RtCRnegw0gVp9zsRP9aNPDW WsUKzX4T6EeelZPKKuk41zGKgL+ImucJHzg01i6FXZSu0jNt3KwlimE6voDFgOFg DfenFh60StnFhSFH0CMJFfnzs2Ffp+YMv752MEPtojkJu3uk2/eTqkenNcIm99fz BCLAxOCKYrU6C8E7MtJJfbngwRQrAod0CXGWt4T4s602WvIGdlNt6A0n6ia6uLa7 1iiVWoVOO/QBJCBhLpdAncG2jDfkZreRw9sU1vEDWHAt71GFMzZEvxNVGxnFhAzU agZzBxvqHC2l5q39SngRqwbnnyexZuPdedbgOj+2wOCLbTwMJnY73sxZsvqMkxpX +uZkVDlazz3q9wLBHk27XmkdDlzGVBW0ytNHhT7zSV/eHs6IDyb28fl+NFBalCtS t72p3ZznOQ4469Pu+sOoAhLgBOLTPfa1m1gWdGJQE/XAzwKySxjnUtJdVXnBVYWo CWf8TtszHy/ZLjFoC7K9L03N5VTdjvXOJRLRTuZXyieUXtgG3ALPeRtKL5cGQ5ti kRl/bBjQvNuxe1RJeaP9Eb1tK/18kJzHzXrT0tAax+KGPe3Hv9YLHmS5zP2zAyeO YhkKfQ43W3o7VlMsWAgcfreGkU9gtDGVdGzzNsMYeqYyED90ZIaQkFZwAXhvGPku 3LOGl8AjOxtLnMDNCRFA =UbGs -----END PGP SIGNATURE----- --9IsjK8UeB7xXCH2NIowIQ4nQSqeMVADVk--