On Fri, Mar 16, 2012 at 06:15:35PM -0400, Chet Ramey wrote: > There is nothing stopping you from using history in a non-interactive > shell -- it's just not enabled by default. > > Turn on history with `set -o history' and set HISTFILE and HISTSIZE as you > like. You can probably set some of the right variables in .ssh/environment > and set BASH_ENV to a file that will run the commands you want.
The problem is, that doesn't actually work. imadev:~$ ssh localhost bash <<'EOF' > set -o history > HISTFILE=~/.bash_history > HISTFILESIZE=500 > echo hello world > EOF wooledg@localhost's password: hello world imadev:~$ tail -2 .bash_history rm statistical.tcl.rej less sched.tcl.rej I blame this part of the documentation, although perhaps I should be looking at the code instead: When an interactive shell exits, the last $HISTSIZE lines are copied from the history list to $HISTFILE. I read that as "the HISTFILE doesn't get updated when a NON-interactive shell exits". This one works, though: imadev:~$ ssh localhost bash <<'EOF' > set -o history > HISTFILE=~/.bash_history > HISTFILESIZE=500 > echo hello world > history -a > EOF wooledg@localhost's password: hello world imadev:~$ tail -6 .bash_history rm statistical.tcl.rej less sched.tcl.rej HISTFILE=~/.bash_history HISTFILESIZE=500 echo hello world history -a However, since the original intent was "I want to log commands that are launched through ssh, without modifying what the client sends", it's not clear to me how to wrap all of that prefix and postfix code around the client's commands.