BASH shell session logging on remote host
Solution 1
It might be worth looking at shell or system auditing programs like rootsh or sudosh.
Solution 2
You could start gnu screen and use the log feature. I don't know of anything that is going to give you a really good log for ncurses applications like top.
man screen
log [on|off]
Start/stop writing output of the current window to a file "screenlog.n"
in the window's default directory, where n is the number of the current
window. This filename can be changed with the `logfile' command. ...
logfile filename
logfile flush secs
Defines the name the log files will get. The default is "screenlog.%n".
The second form changes the number of seconds screen will wait before
flushing the logfile buffer to the file-system. The default value is 10
seconds.
Solution 3
TTYrec is probably the easiest solution. You can use the original:
http://0xcc.net/ttyrec/index.html.en
Or roll your own:
http://en.wikipedia.org/wiki/Ttyrec
Or, you could get all old school and | all your commands to tee command.timestamp.tee
Solution 4
The script
program will take a complete log of your shell session. Dunno if it's equivalent to any PuTTY thing.
Related videos on Youtube
Andy
Full-stack dev, DBA and/or sysadmin Twitter: @sublimino
Updated on September 17, 2022Comments
-
Andy almost 2 years
What's the best method of logging a BASH shell session to a file on the host machine?
The preferred output format would be equivalent to PuTTY's "printable output" log setting, as viewed by the user inclusive of input and exlusive of ncurses control character data.
-
dr.pooter about 15 yearsCurious to know which shell you're using.
-
-
Andy about 15 yearsThanks, but it's not suitable as I spend time on the shell with top open, which screen records as: [andy@165 ~]$ top ESC[HESC[2JESC(BESC[mtop - 23:34:49 up 19 days, 17:42, 1 user, load average: 0.11, 0.07, 0.01ESC(BESC[mESC[39;49mESC[K
-
dr.pooter about 15 yearsThe translation is a bit wonky. Will this handle something like an interactive top process.
-
Andy about 15 yearsPersonal auditing and plain text logging; playback of sessions is not required.
-
Andy about 15 yearsThe output of screen is equivalent to script - ncurses handling appears unsupported.
-
Ketan about 15 yearsscript is the nearest thing to what you want, although as stated it can't deal with ncurses nicely. We use script for logging all sessions and just try to see past the mess that ncurses will make.
-
Andy about 15 yearsThanks Geoff, looks like I might be stuck with script then.
-
TiFFolk about 15 yearsas to picture, it does not handle vi, so no top i think. But logging is pretty attractive.
-
Andy about 15 yearsrootsh turns out to be nearest to what I want, thanks.
-
Mircea Vutcovici over 14 yearsYou can also take in consideration acct/psacct (BSD accounting) or snoopy. They do not log the output, but they are also less verbose. See: cyberciti.biz/tips/… and sourceforge.net/projects/snoopylogger
-
Erik Osterman over 7 yearsThe
rootsh
app is now deprecated andsudosh
seems unmaintained. We implemented a paper-thin wrapper aroundsudo
to allowsudo
to be used as a login shell for the purpose of session logging. See here: github.com/cloudposse/sudosh