storing ssh remote executed command output to variable is blocking. connection not ending? ...

Antler Helmet: Can it work?

Is it true to say that an hosting provider's DNS server is what links the entire hosting environment to ICANN?

How discoverable are IPv6 addresses and AAAA names by potential attackers?

Gastric acid as a weapon

Did Kevin spill real chili?

What makes black pepper strong or mild?

What's the purpose of writing one's academic bio in 3rd person?

Bonus calculation: Am I making a mountain out of a molehill?

What is the musical term for a note that continously plays through a melody?

Disable hyphenation for an entire paragraph

What would be the ideal power source for a cybernetic eye?

∞ symbol in external pdf disappears when used as figure

Why one of virtual NICs called bond0?

Why was the term "discrete" used in discrete logarithm?

3 doors, three guards, one stone

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

Why did the IBM 650 use bi-quinary?

If a contract sometimes uses the wrong name, is it still valid?

How to bypass password on Windows XP account?

What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?

When -s is used with third person singular. What's its use in this context?

Letter Boxed validator

How can I fade player when goes inside or outside of the area?

What happens to sewage if there is no river near by?



storing ssh remote executed command output to variable is blocking. connection not ending?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionWhy *not* parse `ls` (and what do to instead)?Why is my ssh connection unauthorized although I have updated my key on the remote machine?SSH connection timed out. it's not client or server…what now?Why does having cron run a remote command over ssh on a Cisco router get interrupted?SSH Server not answering connection requestsWhy is it not possible to connect to my server using RSA from an Ubuntu machine?SSH to localhost serverSSH won't work before manually restarting networking.serviceAllow user to connect using SSH or SFTP but limit to home dir (Centos7)SSH publickey login permission denied on CENTOS But not on Debianpasswordless ssh to localhost in Ubuntu 16.04





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I'm not quite sure what the issue is. I'm on Kali Linux 2.0 right now, fresh install. The following worked on Ubuntu 14.04 but it's not working anymore (maybe I accidentally changed it?). It looks correct to me, but every time it runs it blocks.



backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1')


This is part of a larger script. $server and $dir are set. When I run the command alone, I get the correct output, but it doesn't end the connection.










share|improve this question
















bumped to the homepage by Community 3 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 2





    just FYI, it works for me on Ubuntu 15.04. I also don't see anything wrong on the first sight.

    – Jakuje
    Oct 15 '15 at 21:36






  • 1





    You may want to quote the $dir expansion, lest you might run into problems if $dir ever expands to a path that contains whitespace or shell metacharacters.

    – a CVn
    Apr 15 '16 at 9:14




















1















I'm not quite sure what the issue is. I'm on Kali Linux 2.0 right now, fresh install. The following worked on Ubuntu 14.04 but it's not working anymore (maybe I accidentally changed it?). It looks correct to me, but every time it runs it blocks.



backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1')


This is part of a larger script. $server and $dir are set. When I run the command alone, I get the correct output, but it doesn't end the connection.










share|improve this question
















bumped to the homepage by Community 3 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 2





    just FYI, it works for me on Ubuntu 15.04. I also don't see anything wrong on the first sight.

    – Jakuje
    Oct 15 '15 at 21:36






  • 1





    You may want to quote the $dir expansion, lest you might run into problems if $dir ever expands to a path that contains whitespace or shell metacharacters.

    – a CVn
    Apr 15 '16 at 9:14
















1












1








1








I'm not quite sure what the issue is. I'm on Kali Linux 2.0 right now, fresh install. The following worked on Ubuntu 14.04 but it's not working anymore (maybe I accidentally changed it?). It looks correct to me, but every time it runs it blocks.



backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1')


This is part of a larger script. $server and $dir are set. When I run the command alone, I get the correct output, but it doesn't end the connection.










share|improve this question
















I'm not quite sure what the issue is. I'm on Kali Linux 2.0 right now, fresh install. The following worked on Ubuntu 14.04 but it's not working anymore (maybe I accidentally changed it?). It looks correct to me, but every time it runs it blocks.



backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1')


This is part of a larger script. $server and $dir are set. When I run the command alone, I get the correct output, but it doesn't end the connection.







bash ssh openssh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 16 '15 at 9:19







sand_storm_of_code.txt

















asked Oct 15 '15 at 20:55









sand_storm_of_code.txtsand_storm_of_code.txt

14117




14117





bumped to the homepage by Community 3 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 3 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 2





    just FYI, it works for me on Ubuntu 15.04. I also don't see anything wrong on the first sight.

    – Jakuje
    Oct 15 '15 at 21:36






  • 1





    You may want to quote the $dir expansion, lest you might run into problems if $dir ever expands to a path that contains whitespace or shell metacharacters.

    – a CVn
    Apr 15 '16 at 9:14
















  • 2





    just FYI, it works for me on Ubuntu 15.04. I also don't see anything wrong on the first sight.

    – Jakuje
    Oct 15 '15 at 21:36






  • 1





    You may want to quote the $dir expansion, lest you might run into problems if $dir ever expands to a path that contains whitespace or shell metacharacters.

    – a CVn
    Apr 15 '16 at 9:14










2




2





just FYI, it works for me on Ubuntu 15.04. I also don't see anything wrong on the first sight.

– Jakuje
Oct 15 '15 at 21:36





just FYI, it works for me on Ubuntu 15.04. I also don't see anything wrong on the first sight.

– Jakuje
Oct 15 '15 at 21:36




1




1





You may want to quote the $dir expansion, lest you might run into problems if $dir ever expands to a path that contains whitespace or shell metacharacters.

– a CVn
Apr 15 '16 at 9:14







You may want to quote the $dir expansion, lest you might run into problems if $dir ever expands to a path that contains whitespace or shell metacharacters.

– a CVn
Apr 15 '16 at 9:14












2 Answers
2






active

oldest

votes


















0














I'm not entirely sure why the command would hang, but you don't need to run the whole pipeline on the server. It's enough to do the ls there:



backup_folder=$( ssh -i keyfile "$server" "ls -t '$dir'" | head -n 1 )


Note that this quotes the $dir value on the remote side (it will still be expanded locally). The head will run locally.



This also comes with the caveats mentioned in the answers to "Why *not* parse `ls`?".






share|improve this answer































    -1














    I have had the same issue recently, probably you should add a redirection to stdout at the end of the command, like so:



    backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1' 2>&1)





    share|improve this answer
























    • That would cause error messages to be part of the $backup_folder string.

      – Kusalananda
      Jun 20 '18 at 13:47












    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    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%2f236503%2fstoring-ssh-remote-executed-command-output-to-variable-is-blocking-connection-n%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I'm not entirely sure why the command would hang, but you don't need to run the whole pipeline on the server. It's enough to do the ls there:



    backup_folder=$( ssh -i keyfile "$server" "ls -t '$dir'" | head -n 1 )


    Note that this quotes the $dir value on the remote side (it will still be expanded locally). The head will run locally.



    This also comes with the caveats mentioned in the answers to "Why *not* parse `ls`?".






    share|improve this answer




























      0














      I'm not entirely sure why the command would hang, but you don't need to run the whole pipeline on the server. It's enough to do the ls there:



      backup_folder=$( ssh -i keyfile "$server" "ls -t '$dir'" | head -n 1 )


      Note that this quotes the $dir value on the remote side (it will still be expanded locally). The head will run locally.



      This also comes with the caveats mentioned in the answers to "Why *not* parse `ls`?".






      share|improve this answer


























        0












        0








        0







        I'm not entirely sure why the command would hang, but you don't need to run the whole pipeline on the server. It's enough to do the ls there:



        backup_folder=$( ssh -i keyfile "$server" "ls -t '$dir'" | head -n 1 )


        Note that this quotes the $dir value on the remote side (it will still be expanded locally). The head will run locally.



        This also comes with the caveats mentioned in the answers to "Why *not* parse `ls`?".






        share|improve this answer













        I'm not entirely sure why the command would hang, but you don't need to run the whole pipeline on the server. It's enough to do the ls there:



        backup_folder=$( ssh -i keyfile "$server" "ls -t '$dir'" | head -n 1 )


        Note that this quotes the $dir value on the remote side (it will still be expanded locally). The head will run locally.



        This also comes with the caveats mentioned in the answers to "Why *not* parse `ls`?".







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 20 '18 at 13:52









        KusalanandaKusalananda

        142k18265440




        142k18265440

























            -1














            I have had the same issue recently, probably you should add a redirection to stdout at the end of the command, like so:



            backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1' 2>&1)





            share|improve this answer
























            • That would cause error messages to be part of the $backup_folder string.

              – Kusalananda
              Jun 20 '18 at 13:47
















            -1














            I have had the same issue recently, probably you should add a redirection to stdout at the end of the command, like so:



            backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1' 2>&1)





            share|improve this answer
























            • That would cause error messages to be part of the $backup_folder string.

              – Kusalananda
              Jun 20 '18 at 13:47














            -1












            -1








            -1







            I have had the same issue recently, probably you should add a redirection to stdout at the end of the command, like so:



            backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1' 2>&1)





            share|improve this answer













            I have had the same issue recently, probably you should add a redirection to stdout at the end of the command, like so:



            backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1' 2>&1)






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 15 '16 at 9:02









            vpapakirvpapakir

            12




            12













            • That would cause error messages to be part of the $backup_folder string.

              – Kusalananda
              Jun 20 '18 at 13:47



















            • That would cause error messages to be part of the $backup_folder string.

              – Kusalananda
              Jun 20 '18 at 13:47

















            That would cause error messages to be part of the $backup_folder string.

            – Kusalananda
            Jun 20 '18 at 13:47





            That would cause error messages to be part of the $backup_folder string.

            – Kusalananda
            Jun 20 '18 at 13:47


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f236503%2fstoring-ssh-remote-executed-command-output-to-variable-is-blocking-connection-n%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...