I'm aware the
script command can be used to record all keyboard input and screen output to a file, but this has to be invoked each time a terminal session is started. I keep timestamped versions of my .bash_history files so old commands aren't lost after $HISTSIZE is reached. My $HISTFILE statement in .bashrc is
HISTFILE=~/.bash_history_$(date '+%Y%m%d_%H_%M_%S_%N').txt. That satisfies my need to create a log of commands executed, but doesn't record the output to a file. Is there something I can put in .bashrc or .profile that will record all stdin input, and stdout & stderr output to a timestamped file? This would be handy to monitor user activity as well, but I just need it to reference in the future.
EDIT: I found that if I put
script /ramdisk/consoleOutput_$(whoami)_$(date +'%Y_%m_%d_%H_%M_%S_%N').txt ; exit
at the end of ~/.profile, for a test user, this behaved like I want.
;exit after the
script command exits from the terminal. Typing "exit" when the user is logged in exits the
script session. When that exits from ~/.profile, the extra "exit" then quits the SSH/terminal session. I plan on creating additional functionality which will
chown the file to root and
chmod 600 so only root can read it. From there, it'll be moved to a secure location.
Furthermore, the coloring is visible with
more. Opening it in an editor shows the control characters used to generate the color. I'm okay with that.