Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ssh host 'history | tail' produces no output

Tags:

bash

ssh

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
like image 931
jonderry Avatar asked Oct 26 '25 03:10

jonderry


1 Answers

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
like image 82
Dennis Williamson Avatar answered Oct 28 '25 03:10

Dennis Williamson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!