jonderry
jonderry

Reputation: 23633

ssh host 'history | tail' produces no output

Can anyone explain the following? When I use ssh to execute history remotely, no output is produced, even other remote commands do produce output and there is history on that machine.

ssh host 'history | tail' # produces no output
ssh host 'echo foo | tail' # produces 'foo' as output
ssh host
> history | tail # produces expected output

Upvotes: 4

Views: 1662

Answers (1)

Dennis Williamson
Dennis Williamson

Reputation: 360105

History is not loaded for a non-interactive shell. You can either tail the history file (~/.bash_history) or turn on history and load it.

set -o history
history -r

The full commands needed to do this from the remote host is as follows:

ssh host 'HISTFILE=~/.bash_history; history -r; history' | tail

Upvotes: 6

Related Questions