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.
Try using ssh -T "username@"host" "cat foo.txt"
-T stops a pseudo-tty terminal being assigned
or failing that try
echo "cat foo.txt" | ssh "username"@"host"
which should just work like ssh "username"@"host" "cat foo.txt"
just thought of another one instead of the echo, try using
ssh -t -t "username"@"host" "cat foo.txt"
Best Answer
If you enter the following into
.bashrc
(or/etc/profile
, or.profile
, or any other start-up script) on the remote machine:You can replace the
xmessage
command with anything you want: if you use/etc/profile
you will need to make checks thatbash
is in a remote session, so as not to affect local sessions.The answers here deal with exiting scripts, but are equally valid for the shell itself.