This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Logging all console activity to a text file

Hussein Patwa wrote:

> I'd like to log all console activity, both input and output to a text file
> for later review.  Uses for this could be, for example, demonstrating an
> operation to someone unfamiliar with cygwin, or say, keeping a record of
> console output for future reference.

You should try the 'script' command from the util-linux package.  It
will capture all input and output from a terminal.  Note that the file
it produces really is an exact replica, containing all the terminal
escape sequences as well as all keypresses (i.e. typos+backspaces
included.)  Because of that if you try to view it with 'less' or edit it
with a text editor sometimes it will look like garbage.  The only real
reliable way of viewing it is to cat it to the terminal, or strip out
the terminal escape sequences.  There is also the 'replayscript' command
but that is more oriented towards playing back the session with timing

Another thing to be aware of when using 'script' is that it runs the
commands attached to a pty (pseudoterminal), which is how it intercepts
all I/O.  This is normally not an issue, but it can be a problem if
you're running non-Cygwin commands.  The reason is that native apps
don't understand ptys, they think their stdin and stdout are pipes and
therefore sometimes interactive input doesn't work or output is
buffered.  If you are already using rxvt/xterm or have CYGWIN=tty then
you're already using ptys so it will be no change.

Some terminals also have a logging capability.  For example xterm has
the -l option.  This only logs the output, altough that may not be an
issue since every character you type is also echoed to stdout by the
shell -- that's how you see what you've typed.  I think putty has a
similar option.

> Can this be done either globally (logging start each time a cygwin session
> starts), or individually (I can start and stop logging as I choose) and if
> so how?

If you wanted 'script' to log everything for every session by default,
you could add it as the last command in the user's profile or the system
profile -- or you could just change the command that starts the Cygwin
session (normally cygwin.bat) to run script explicitly.  You may have to
use some logic to pick a unquely named filename each time, e.g. using
the date command.

If you want to start and stop logging, it works just like invoking a
subshell, i.e. type "script filename", enter some commands, type exit,
logging stops.


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]