Some commands not working when executed via ssh while redirecting output locally
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
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?
bash ssh command-history
add a comment |Â
up vote
1
down vote
favorite
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?
bash ssh command-history
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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?
bash ssh command-history
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?
bash ssh command-history
bash ssh command-history
edited Sep 10 at 23:01
Jeff Schaller
33.1k849111
33.1k849111
asked Sep 10 at 22:56
onlineoffline
153
153
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
history
is an internal command to bash, so you don't want to run the executable history
, you want to run the executable bash
. ls
works because is an executable on its own, usually at /bin/ls
.
Besides that, by default bash disables the history in non-interactive shells, as is the case when you run a remote command.
You can create a shell script in the remote machine to enable it and run history, example:
#!/usr/bin/bash
HISTFILE=~/.bash_history
set -o history
history
Or, if you really want to do all that from the ssh call, you can do:
ssh user@remote.ip 'echo -e "HISTFILE=~/.bash_historynset -o historynhistory" | bash'
Note that it also doesn't take into account the HISTTIMEFORMAT
variable, if you use it in the remote machine, so plan for that.
References: History command inside bash script
what would a working command look like?ssh user@remote.ip "bash history" > testhistory.txt
doesn't work
â onlineoffline
Sep 10 at 23:24
1
ssh
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 at 3:17
Is there a way to make all variables enabled or find out what's disabled when in non-interactive shell?
â onlineoffline
Sep 11 at 19:10
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
history
is an internal command to bash, so you don't want to run the executable history
, you want to run the executable bash
. ls
works because is an executable on its own, usually at /bin/ls
.
Besides that, by default bash disables the history in non-interactive shells, as is the case when you run a remote command.
You can create a shell script in the remote machine to enable it and run history, example:
#!/usr/bin/bash
HISTFILE=~/.bash_history
set -o history
history
Or, if you really want to do all that from the ssh call, you can do:
ssh user@remote.ip 'echo -e "HISTFILE=~/.bash_historynset -o historynhistory" | bash'
Note that it also doesn't take into account the HISTTIMEFORMAT
variable, if you use it in the remote machine, so plan for that.
References: History command inside bash script
what would a working command look like?ssh user@remote.ip "bash history" > testhistory.txt
doesn't work
â onlineoffline
Sep 10 at 23:24
1
ssh
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 at 3:17
Is there a way to make all variables enabled or find out what's disabled when in non-interactive shell?
â onlineoffline
Sep 11 at 19:10
add a comment |Â
up vote
2
down vote
accepted
history
is an internal command to bash, so you don't want to run the executable history
, you want to run the executable bash
. ls
works because is an executable on its own, usually at /bin/ls
.
Besides that, by default bash disables the history in non-interactive shells, as is the case when you run a remote command.
You can create a shell script in the remote machine to enable it and run history, example:
#!/usr/bin/bash
HISTFILE=~/.bash_history
set -o history
history
Or, if you really want to do all that from the ssh call, you can do:
ssh user@remote.ip 'echo -e "HISTFILE=~/.bash_historynset -o historynhistory" | bash'
Note that it also doesn't take into account the HISTTIMEFORMAT
variable, if you use it in the remote machine, so plan for that.
References: History command inside bash script
what would a working command look like?ssh user@remote.ip "bash history" > testhistory.txt
doesn't work
â onlineoffline
Sep 10 at 23:24
1
ssh
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 at 3:17
Is there a way to make all variables enabled or find out what's disabled when in non-interactive shell?
â onlineoffline
Sep 11 at 19:10
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
history
is an internal command to bash, so you don't want to run the executable history
, you want to run the executable bash
. ls
works because is an executable on its own, usually at /bin/ls
.
Besides that, by default bash disables the history in non-interactive shells, as is the case when you run a remote command.
You can create a shell script in the remote machine to enable it and run history, example:
#!/usr/bin/bash
HISTFILE=~/.bash_history
set -o history
history
Or, if you really want to do all that from the ssh call, you can do:
ssh user@remote.ip 'echo -e "HISTFILE=~/.bash_historynset -o historynhistory" | bash'
Note that it also doesn't take into account the HISTTIMEFORMAT
variable, if you use it in the remote machine, so plan for that.
References: History command inside bash script
history
is an internal command to bash, so you don't want to run the executable history
, you want to run the executable bash
. ls
works because is an executable on its own, usually at /bin/ls
.
Besides that, by default bash disables the history in non-interactive shells, as is the case when you run a remote command.
You can create a shell script in the remote machine to enable it and run history, example:
#!/usr/bin/bash
HISTFILE=~/.bash_history
set -o history
history
Or, if you really want to do all that from the ssh call, you can do:
ssh user@remote.ip 'echo -e "HISTFILE=~/.bash_historynset -o historynhistory" | bash'
Note that it also doesn't take into account the HISTTIMEFORMAT
variable, if you use it in the remote machine, so plan for that.
References: History command inside bash script
edited Sep 10 at 23:31
answered Sep 10 at 23:16
msb
1,15079
1,15079
what would a working command look like?ssh user@remote.ip "bash history" > testhistory.txt
doesn't work
â onlineoffline
Sep 10 at 23:24
1
ssh
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 at 3:17
Is there a way to make all variables enabled or find out what's disabled when in non-interactive shell?
â onlineoffline
Sep 11 at 19:10
add a comment |Â
what would a working command look like?ssh user@remote.ip "bash history" > testhistory.txt
doesn't work
â onlineoffline
Sep 10 at 23:24
1
ssh
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 at 3:17
Is there a way to make all variables enabled or find out what's disabled when in non-interactive shell?
â onlineoffline
Sep 11 at 19:10
what would a working command look like?
ssh user@remote.ip "bash history" > testhistory.txt
doesn't workâ onlineoffline
Sep 10 at 23:24
what would a working command look like?
ssh user@remote.ip "bash history" > testhistory.txt
doesn't workâ onlineoffline
Sep 10 at 23:24
1
1
ssh
with additional non-option arguments passes them to the remote shell (all as one -c
) so builtins DO work (try ssh u@h declare -p
); noninteractive -> disable history is the only issue. And you don't need the remote shell to run yet another, just ssh 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 at 3:17
ssh
with additional non-option arguments passes them to the remote shell (all as one -c
) so builtins DO work (try ssh u@h declare -p
); noninteractive -> disable history is the only issue. And you don't need the remote shell to run yet another, just ssh 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 at 3:17
Is there a way to make all variables enabled or find out what's disabled when in non-interactive shell?
â onlineoffline
Sep 11 at 19:10
Is there a way to make all variables enabled or find out what's disabled when in non-interactive shell?
â onlineoffline
Sep 11 at 19:10
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468130%2fsome-commands-not-working-when-executed-via-ssh-while-redirecting-output-locally%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password