Friday, August 31, 2007

Good habits: lengthen your history

It's important to know what you've done, as a sysadmin. If you're one of a group of admins, history becomes even more important.

The first thing I do on a legacy Linux system, is edit /etc/profile, and change HISTSIZE to 100000 or more. Note, this does not erase previous history (although etting it to zero will).

Of course, "history" records only one side of the conversation. The responses of the machine are just as important. Unfortunately, there's no straightforward mechanism like history, which would automatically log everything you see. Your terminal client can often do this for you, but it would be nice to do it on the machine itself.

To bug the bash people about this, for their next release, go here.

The "script" command is a temporary fix ... it records your session in a transcript file. You type "exit" or ^d to stop recording. It writes into a file called "typescript", unless you specify something different.

Trying to automate this:

... you cannot just put "script" in your .bashrc file ... it will go into an infinite loop, because "script" itself starts a new shell (when you stop this, amusingly, you'll find yourself at the bottom of a few hundred nested shells ...)

You can't put it in .login ... because script starts a shell. When .login exits, so will the "script" shell. But that's not what you need.

What you need to do, is set an environmental variable in .bash_login, unset it in .basrc, and then start "script" just once.


Post a Comment

<< Home