Inputs and outputs in the right order

Martin McCormick martin at
Fri Nov 1 03:24:06 UTC 2013

	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.

	If you do that, however, there is an interesting
problem. If one was to manually enter commands to the shell, the
output looks like:

shell_output for one or more lines and then

	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.

	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.

	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?

Thanks for any and all constructive ideas.

Martin McCormick

More information about the freebsd-questions mailing list