Bash history with timestamp

Very often we are working on shared environments. And very often we are hearing “It wasn’t me…” when we are trying to identify who executed what.

We can get list of logged users from the last command, but how to linked these outputs with the list of commands from history? And/or how to push all commands to be written in history when users are using tmux or screen?

For me the easiest way was following sh script pushing setting in /etc/profile.d/bash_history.sh

I think the comments are self-explaining. 
Adding timestamp, avoiding duplicates, appending history and immediately update the history.

No need to set X attribute to the file – it will be executed automatically after each login and the output looks like this:

BTW one last note to mention – when you enable the history timestamp it is going to be applied to all records already stored in history with the time and date of the first command after new setup. 

So it will looks like this


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *