History with Session info

Hello Unix Gurus,

I am in the need to capture the terminal info a command was executed from in the history. Currently history lists only the time and command, but does not list the terminal that can help associate the command to an individual.

So my ask is - is there a way to capture/append the terminal info (we can map the terminal to the connecting session/user form the authlog or similar) to the history command?

Thanks,
aBBy007

Only if you rewrite the shell(s) that add data into the history file you are processing. The history (usually a shell built-in) utility doesn't write anything into a history file; it just reads and formats the data it finds there. In some shells the history utility may also be used to discard old history entries. But, it can't determine who added history entries to a history file after those entries have been written.

Isn't the history file saved in the respective user's home directory?

By default, yes. But if the HISTFILE variable is set before the 1st interactive command is executed by a shell, the pathname in that variable will be used instead of $HOME/.sh_history if the user running that shell has the privileges needed to create and/or write to that pathname.

1 Like