# Logging terminal input for documentation purposes



## Mattias (Sep 15, 2011)

It would be neat with a way to log all terminal input (or simply executed commands with arguments). Logging should preferably be done to an specified file and only when invoked by the user. Output should be easily filtered, or rather omitted completely (output from building wouldn't do much good post-install I reckon). All this to keep track of maintenance work for reproduction/documentation.

A spontaneously thought is utilizing shell history by changing the the history settings (file, recurring entries, etc) and shell prompt to indicate active logging. If executable that method would only log executed commands (not movement or other input in programs).

A keylogger probably produce way to verbose logs (experience someone?).


----------



## fluca1978 (Sep 15, 2011)

I assume you want to log one-shot commands, not complicated sessions like for instance sysinstall. Isn't the script command enough for you? However writing a small command wrapper in C/Perl/sh to dump the command line (and other info such as user, time, ecc.) to a file should not be too complicated.


----------



## wblock@ (Sep 15, 2011)

script(1) logs everything, including stderr and also stuff you probably don't want like escape sequences and control characters.  Easier to filter that from the log than try to recreate output manually.  Showing at least the first and last few lines of a command's output is useful to let the user know what should happen.


----------



## jalla (Sep 15, 2011)

I suggest an alias like this
`alias logsession 'script && grep "^snapper" typescript > \!$.log && rm typescript'`
(make sure the grep-pattern is a distinct part of your cmdprompt)

Whenever you want to log a series of commands:
`logsession <mysession>`


----------



## swallowtail_butterfly (Sep 15, 2011)

There are also *-r*/*-p* extensions from NetBSD that allows you to record interactive sessions with ncurses apps, see PR bin/114465. With them you can record smth like vim/emacs tutorial, e.g.
`$ script -r`
`$ vim`
do some tricks here
`$ exit`

and to play
`$ script -p`


----------



## wblock@ (Sep 15, 2011)

Forgot to add that the shell can tell if script is running by checking for the SCRIPT variable.  That could be used to show a different prompt.  ("Everything you type is being recorded!")


----------

