use ssh result in local program
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I'm trying to run a script on a remote machine with ssh and receive the result,
I tried:
sh -c "ssh 192.168.2.202 /etc/my_script.sh arg1 arg2 > result.txt 2>/dev/null "
as suggested in this answer Redirect stdout over ssh but if I don't redirect STDERR I get:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Inappropriate ioctl for device
Is there a better way ? In the end I need to run ssh from inside a program - by system call and be able to receive the result in a file or a variable
Note: connecting to a uProcessor that has a skinny linux ubunto loaded with dropbear ssh
shell-script ssh system-calls
 |Â
show 2 more comments
up vote
-1
down vote
favorite
I'm trying to run a script on a remote machine with ssh and receive the result,
I tried:
sh -c "ssh 192.168.2.202 /etc/my_script.sh arg1 arg2 > result.txt 2>/dev/null "
as suggested in this answer Redirect stdout over ssh but if I don't redirect STDERR I get:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Inappropriate ioctl for device
Is there a better way ? In the end I need to run ssh from inside a program - by system call and be able to receive the result in a file or a variable
Note: connecting to a uProcessor that has a skinny linux ubunto loaded with dropbear ssh
shell-script ssh system-calls
no, result.txt is on the local machine i.e. the machine from which i'm running the command @Jesse_b
â Meir
Feb 25 at 15:15
1
Is there any reason you are usingsh -c
? That isn't suggested at all in your linked question. I cannot reproduce your results though. Works fine for me using macos to centos.
â Jesse_b
Feb 25 at 15:19
It could be a issue of the host ssh. saw the sh -c solution herehttps://unix.stackexchange.com/questions/297438/capture-stdout-from-ssh-session-to-local-machine?rq=1 @Jesse_b
â Meir
Feb 25 at 15:32
Do you get the same error if you runsh -c pwd
orsh -c "ssh 192.168.2.202 pwd"
?
â Mark Plotnick
Feb 25 at 15:40
1
It looks like there's a problem on the remote system that's independent of ssh and redirection. Maybe the home directory or one of its parents on the remote system is denying access to the user. Or one of the mount points on the remote system is broken. Can you login to the remote system interactively without any errors?
â Mark Plotnick
Feb 25 at 22:00
 |Â
show 2 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I'm trying to run a script on a remote machine with ssh and receive the result,
I tried:
sh -c "ssh 192.168.2.202 /etc/my_script.sh arg1 arg2 > result.txt 2>/dev/null "
as suggested in this answer Redirect stdout over ssh but if I don't redirect STDERR I get:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Inappropriate ioctl for device
Is there a better way ? In the end I need to run ssh from inside a program - by system call and be able to receive the result in a file or a variable
Note: connecting to a uProcessor that has a skinny linux ubunto loaded with dropbear ssh
shell-script ssh system-calls
I'm trying to run a script on a remote machine with ssh and receive the result,
I tried:
sh -c "ssh 192.168.2.202 /etc/my_script.sh arg1 arg2 > result.txt 2>/dev/null "
as suggested in this answer Redirect stdout over ssh but if I don't redirect STDERR I get:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Inappropriate ioctl for device
Is there a better way ? In the end I need to run ssh from inside a program - by system call and be able to receive the result in a file or a variable
Note: connecting to a uProcessor that has a skinny linux ubunto loaded with dropbear ssh
shell-script ssh system-calls
edited Feb 25 at 15:16
asked Feb 25 at 14:59
Meir
765
765
no, result.txt is on the local machine i.e. the machine from which i'm running the command @Jesse_b
â Meir
Feb 25 at 15:15
1
Is there any reason you are usingsh -c
? That isn't suggested at all in your linked question. I cannot reproduce your results though. Works fine for me using macos to centos.
â Jesse_b
Feb 25 at 15:19
It could be a issue of the host ssh. saw the sh -c solution herehttps://unix.stackexchange.com/questions/297438/capture-stdout-from-ssh-session-to-local-machine?rq=1 @Jesse_b
â Meir
Feb 25 at 15:32
Do you get the same error if you runsh -c pwd
orsh -c "ssh 192.168.2.202 pwd"
?
â Mark Plotnick
Feb 25 at 15:40
1
It looks like there's a problem on the remote system that's independent of ssh and redirection. Maybe the home directory or one of its parents on the remote system is denying access to the user. Or one of the mount points on the remote system is broken. Can you login to the remote system interactively without any errors?
â Mark Plotnick
Feb 25 at 22:00
 |Â
show 2 more comments
no, result.txt is on the local machine i.e. the machine from which i'm running the command @Jesse_b
â Meir
Feb 25 at 15:15
1
Is there any reason you are usingsh -c
? That isn't suggested at all in your linked question. I cannot reproduce your results though. Works fine for me using macos to centos.
â Jesse_b
Feb 25 at 15:19
It could be a issue of the host ssh. saw the sh -c solution herehttps://unix.stackexchange.com/questions/297438/capture-stdout-from-ssh-session-to-local-machine?rq=1 @Jesse_b
â Meir
Feb 25 at 15:32
Do you get the same error if you runsh -c pwd
orsh -c "ssh 192.168.2.202 pwd"
?
â Mark Plotnick
Feb 25 at 15:40
1
It looks like there's a problem on the remote system that's independent of ssh and redirection. Maybe the home directory or one of its parents on the remote system is denying access to the user. Or one of the mount points on the remote system is broken. Can you login to the remote system interactively without any errors?
â Mark Plotnick
Feb 25 at 22:00
no, result.txt is on the local machine i.e. the machine from which i'm running the command @Jesse_b
â Meir
Feb 25 at 15:15
no, result.txt is on the local machine i.e. the machine from which i'm running the command @Jesse_b
â Meir
Feb 25 at 15:15
1
1
Is there any reason you are using
sh -c
? That isn't suggested at all in your linked question. I cannot reproduce your results though. Works fine for me using macos to centos.â Jesse_b
Feb 25 at 15:19
Is there any reason you are using
sh -c
? That isn't suggested at all in your linked question. I cannot reproduce your results though. Works fine for me using macos to centos.â Jesse_b
Feb 25 at 15:19
It could be a issue of the host ssh. saw the sh -c solution herehttps://unix.stackexchange.com/questions/297438/capture-stdout-from-ssh-session-to-local-machine?rq=1 @Jesse_b
â Meir
Feb 25 at 15:32
It could be a issue of the host ssh. saw the sh -c solution herehttps://unix.stackexchange.com/questions/297438/capture-stdout-from-ssh-session-to-local-machine?rq=1 @Jesse_b
â Meir
Feb 25 at 15:32
Do you get the same error if you run
sh -c pwd
or sh -c "ssh 192.168.2.202 pwd"
?â Mark Plotnick
Feb 25 at 15:40
Do you get the same error if you run
sh -c pwd
or sh -c "ssh 192.168.2.202 pwd"
?â Mark Plotnick
Feb 25 at 15:40
1
1
It looks like there's a problem on the remote system that's independent of ssh and redirection. Maybe the home directory or one of its parents on the remote system is denying access to the user. Or one of the mount points on the remote system is broken. Can you login to the remote system interactively without any errors?
â Mark Plotnick
Feb 25 at 22:00
It looks like there's a problem on the remote system that's independent of ssh and redirection. Maybe the home directory or one of its parents on the remote system is denying access to the user. Or one of the mount points on the remote system is broken. Can you login to the remote system interactively without any errors?
â Mark Plotnick
Feb 25 at 22:00
 |Â
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
This works:
ssh user@host "<cmd> > output.txt 2>/dev/null"
I believe the problem you have is the inability to isolate the command sent to the SSH shell vs the parameters interpreted by 'sh -c'.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
This works:
ssh user@host "<cmd> > output.txt 2>/dev/null"
I believe the problem you have is the inability to isolate the command sent to the SSH shell vs the parameters interpreted by 'sh -c'.
add a comment |Â
up vote
1
down vote
This works:
ssh user@host "<cmd> > output.txt 2>/dev/null"
I believe the problem you have is the inability to isolate the command sent to the SSH shell vs the parameters interpreted by 'sh -c'.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
This works:
ssh user@host "<cmd> > output.txt 2>/dev/null"
I believe the problem you have is the inability to isolate the command sent to the SSH shell vs the parameters interpreted by 'sh -c'.
This works:
ssh user@host "<cmd> > output.txt 2>/dev/null"
I believe the problem you have is the inability to isolate the command sent to the SSH shell vs the parameters interpreted by 'sh -c'.
answered Feb 25 at 17:38
Pedro
59429
59429
add a comment |Â
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%2f426472%2fuse-ssh-result-in-local-program%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
no, result.txt is on the local machine i.e. the machine from which i'm running the command @Jesse_b
â Meir
Feb 25 at 15:15
1
Is there any reason you are using
sh -c
? That isn't suggested at all in your linked question. I cannot reproduce your results though. Works fine for me using macos to centos.â Jesse_b
Feb 25 at 15:19
It could be a issue of the host ssh. saw the sh -c solution herehttps://unix.stackexchange.com/questions/297438/capture-stdout-from-ssh-session-to-local-machine?rq=1 @Jesse_b
â Meir
Feb 25 at 15:32
Do you get the same error if you run
sh -c pwd
orsh -c "ssh 192.168.2.202 pwd"
?â Mark Plotnick
Feb 25 at 15:40
1
It looks like there's a problem on the remote system that's independent of ssh and redirection. Maybe the home directory or one of its parents on the remote system is denying access to the user. Or one of the mount points on the remote system is broken. Can you login to the remote system interactively without any errors?
â Mark Plotnick
Feb 25 at 22:00