I need to list out all the commands executed in a "ssh session". I use multiple ssh session to login to remote servers. So, when I logout from one session, I need to get the commands executed in that session.
Is there any option for that?
If you're running bash on the remote servers, it keeps history for you, and you can retrieve that history with the
If you edit ~/.bash_profile to include the following line:
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
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
to your login scripts. When HISTFILE isn't set, bash won't save the history to a file. This will mean that the
Using PuTTY (or other ssh clients), you can configure it to "save" all the session information.
Another option could be to execute the command
Before leaving the ssh session and downloading the
That would list the last executed commands.
You can even let history know how many commands to remember
Hope that helps
Gonzalo Murillo's 2nd suggestion to use the history command to capture only what you typed (not the command output) will work.
If you want to build a list of commands before connecting to any of the servers, you could script this easily using python to automate the whole thing if you don't need any interaction.