Monday, February 11, 2013

history with timestamp

History is a common command for shell to list out all the executed commands.
It is very useful when it comes to investigation on what commands was
executed that tear down the server. With the help of *last* command, you be
able to track the login time of particular user as well as the the duration
of the time he/she stays login

[image: last cmd.bmp]

If the command line history could provides the date time of the commands
being executed, that may really narrow down the scope of the user actions
that cause the server malfunction. By default, history do not append with
timestamp, but it is easy to configure it to display timestamp, you just
need to set one environment variable *HISTTIMEFORMAT*.

*HISTTIMEFORMAT* takes format string of *strftime*. Check out the strftime
manual to choose and construct the timestamp that suit your taste. My
favorite is “%F %T “.

*HISTTIMEFORMAT* takes format string of *strftime*. Check out the strftime
manual to choose and construct the timestamp that suit your taste. My
favorite is “%F %T “.

[image: 1.bmp]
Execute *history* again and you will see the effect on the spot, bare in
mind that the timestamp for command lines that executed at previous sessions
may not valid, as the time was not tracked.

[image: 2.bmp]

you to put the export into ~/.bash_profile as well as /root/.bash_profile.
In case you do not have .bash_profile, you can choose to put into ~/.bashrc.


No comments:

Post a Comment