Could you share a gist of that? Would love similar thing in my toolset!
I don't do it with code, it's a feature of this product: https://www.vandyke.com/products/securecrt/
Re:How and Why to Log Your Bash History
by tetraodonpuffer on Tuesday May 31, 2016 @11:28AM
(#11807087)
not the OP, but this discussion might be helpful
http://unix.stackexchange.com/questions/25639/how-to-automat...
I have been wondering about doing something like this as well
How do you do this?
Session logging with this client: https://www.vandyke.com/products/securecrt/
This could be done using
script
as well.script gives you the whole console, including output and control characters. It's a useful tool but might be a little overkill for keeping track of what commands you have run.
One time it saved me from a crontab -r that wiped out a 100+ line crontab. I had viewed it recently so I just copied it out of my history.
On a day to day basis it's more about looking up old queries I typed out, the results of those queries at that time, bash commands and their results, the state of a file I edited at a certain time, a stack trace, the output of an ls -l command, etc. Anything I ever do in a session.
Some of those have their own logs or ways to capture history, but a way to capture everything at once is much more comprehensive and less sensitive to forgetting to set the size of the bash history on a given machine, archiving the bash/psql history files when a machine goes away, etc.
And besides not having to worry about the availability of distributed history/log data, being able to grep everything at once is invaluable.