Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is what I am looking for:

A way to log individual SSH sessions on SunOS. I would like to have the files kept separate based upon the hostname of the device I am SSHing into. I am only using the CLI interface so GUI tools will not work. Some of the options I am considering include either using the script command or the screen utility. If someone could explain how they log multiple sessions to multiple devices via an automated method. So for example if you could include either a .bashrc example or a script that I could use so I am not manually entering the same commands every time I login that would be ideal.

I was thinking perhaps a script could first call either screen or script and begin the logging based on the hostname I am SSHing into and then call SSH to start the connection. Thanks!

share|improve this question
up vote 1 down vote accepted

To create a raw logfile of everything that occurs during a session, including screen control escape codes, I would use tee.

In your .bashrc create a function:

myssh () { ssh $1 2>&1 | tee -a ~myusername/logdir/$1.log; }

And then create an alias:

alias ssh=myssh

Now, assuming you have created logdir, anytime you make an ssh connection, the contents of your session will be appended to the logfile based on the connection name.

share|improve this answer
Do you get a load of control characters, in you log? Back-spaces, and new-line converted to new-line + carage-return. – richard Jul 14 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .