-1

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

  • no, result.txt is on the local machine i.e. the machine from which i'm running the command @Jesse_b – Meir Feb 25 '18 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 '18 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 '18 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 '18 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 '18 at 22:00
1

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'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.