use ssh result in local program

The name of the pictureThe name of the pictureThe name of the pictureClash 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







share|improve this question






















  • 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 or sh -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














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







share|improve this question






















  • 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 or sh -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












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







share|improve this question














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









share|improve this question













share|improve this question




share|improve this question








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 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 or sh -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






  • 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 or sh -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










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






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    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






























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






    share|improve this answer
























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






      share|improve this answer






















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






        share|improve this answer












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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 25 at 17:38









        Pedro

        59429




        59429






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?