How to get the commands issued in a ssh session
Solution 1:
If you're running bash on the remote servers, it keeps history for you, and you can retrieve that history with the history
command.
If you edit ~/.bash_profile to include the following line:
export HISTTIMEFORMAT="%h/%d -- %H:%M:%S "
your history will also have timestamps (to make it easier to figure what you ran in the current session, and what's ancient history).
As bash is shutting down, it will run your ~/.bash_logut
script. If you make the last line of this script:
history
the last thing you'll have blurted at you as you're closing the connection will be your history - not just from the current session, unfortunately, but the timestamps should help you figure out which commands were from the current session and which were old.
If you don't mind losing history on the remote machines between sessions, you could add
unset HISTFILE
to your login scripts. When HISTFILE isn't set, bash won't save the history to a file. This will mean that the history
that runs on logout can only show you the current session.