Date: Fri, 01 Nov 2013 06:48:18 +0000 From: Matthew Seaman <matthew@FreeBSD.org> To: freebsd-questions@freebsd.org Subject: Re: Inputs and outputs in the right order Message-ID: <52734EB2.9010207@FreeBSD.org> In-Reply-To: <201311010256.rA12u1jx009134@x.it.okstate.edu> References: <201311010256.rA12u1jx009134@x.it.okstate.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?52734EB2.9010207>
