BASH shell session logging on remote host

5,761

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.

Share:
5,761

Related videos on Youtube

Andy
Author by

Andy

Full-stack dev, DBA and/or sysadmin Twitter: @sublimino

Updated on September 17, 2022

Comments

  • Andy
    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
      dr.pooter about 15 years
      Curious to know which shell you're using.
  • Andy
    Andy about 15 years
    Thanks, 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
    dr.pooter about 15 years
    The translation is a bit wonky. Will this handle something like an interactive top process.
  • Andy
    Andy about 15 years
    Personal auditing and plain text logging; playback of sessions is not required.
  • Andy
    Andy about 15 years
    The output of screen is equivalent to script - ncurses handling appears unsupported.
  • Ketan
    Ketan about 15 years
    script 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
    Andy about 15 years
    Thanks Geoff, looks like I might be stuck with script then.
  • TiFFolk
    TiFFolk about 15 years
    as to picture, it does not handle vi, so no top i think. But logging is pretty attractive.
  • Andy
    Andy about 15 years
    rootsh turns out to be nearest to what I want, thanks.
  • Mircea Vutcovici
    Mircea Vutcovici over 14 years
    You 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
    Erik Osterman over 7 years
    The rootsh app is now deprecated and sudosh seems unmaintained. We implemented a paper-thin wrapper around sudo to allow sudo to be used as a login shell for the purpose of session logging. See here: github.com/cloudposse/sudosh