I can run the following two commands for example and get the output locally:
ssh user@remote.ip ls > testhistory.txt
ssh user@remote.ip "cat .bash_history" > testhistory.txt
But if I run the following command, the local output is always empty:
ssh user@remote.ip history > testhistory.txt
If I ssh
to the remote destination and then run the history
command, i get the expected output.
Why does the history
command not output results when run inline with ssh
but the ls
command works normally? What do i need to change to make the history
command output results to local file the way I did the ls
command without having to cat
the .bash_history
file?
ssh user@remote.ip "bash history" > testhistory.txt
doesn't work – Sep 10 '18 at 23:24ssh
with additional non-option arguments passes them to the remote shell (all as one-c
) so builtins DO work (tryssh u@h declare -p
); noninteractive -> disable history is the only issue. And you don't need the remote shell to run yet another, justssh u@h 'HISTFILE=~/.bash_history; set -o history; history'
-- or even quote only the semicolons:ssh u@h HISTFILE=~/.bash_history';'set -o history';'history
but that looks really odd – dave_thompson_085 Sep 11 '18 at 03:17