Ssh exit code not working within functionSSH client not showing prompt after successful loginbash function...

How do you make a gun that shoots melee weapons and/or swords?

Is there a math expression equivalent to the conditional ternary operator?

Draw this image in the TIKZ package

How would an energy-based "projectile" blow up a spaceship?

Are small insurances worth it?

After Brexit, will the EU recognize British passports that are valid for more than ten years?

How strong is the axiom of well-ordered choice?

A running toilet that stops itself

How spaceships determine each other's mass in space?

PTIJ: Sport in the Torah

Was it really inappropriate to write a pull request for the company I interviewed with?

A vote on the Brexit backstop

Can inspiration allow the Rogue to make a Sneak Attack?

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Can I challenge the interviewer to give me a proper technical feedback?

Is it a Cyclops number? "Nobody" knows!

Boss Telling direct supervisor I snitched

Can Witch Sight see through Mirror Image?

“I had a flat in the centre of town, but I didn’t like living there, so …”

Is this Paypal Github SDK reference really a dangerous site?

Should I file my taxes? No income, unemployed, but paid 2k in student loan interest

How to distinguish easily different soldier of ww2?

Help! My Character is too much for her story!

What does it take to become a wilderness skills guide as a business?



Ssh exit code not working within function


SSH client not showing prompt after successful loginbash function with sshSSH not seeming to run in bash script called via web servernodename nor servname provided, or not knownPasswordless SSH not working - keys copied and permissions setgenerate ssh host keys for clients on puppetmasterRsync over SSH getting no tty presentHow can I return a specific exit code on the Linux command line?pssh stderr askpass received promptSSH connection automatically closed when a command returns an exit status different from 0













0















So I have a function that looks like this. It's an oversimplified example but its enough to demonstrate my issue.



For some reason, I can not get the exit status of the ssh remote command. It does not matter if I give exit 0, or true or if I give a command that throws a success command, the end result is the same, I always get 1.



The thing is, this code works perfectly when ran from a script, but not if I do it from a function.



function hello(){
while read user password
do
ssh -n -q user@host 'exit 0' ; echo $?
done <<< "$( cat creds.txt )"
}








share



























    0















    So I have a function that looks like this. It's an oversimplified example but its enough to demonstrate my issue.



    For some reason, I can not get the exit status of the ssh remote command. It does not matter if I give exit 0, or true or if I give a command that throws a success command, the end result is the same, I always get 1.



    The thing is, this code works perfectly when ran from a script, but not if I do it from a function.



    function hello(){
    while read user password
    do
    ssh -n -q user@host 'exit 0' ; echo $?
    done <<< "$( cat creds.txt )"
    }








    share

























      0












      0








      0








      So I have a function that looks like this. It's an oversimplified example but its enough to demonstrate my issue.



      For some reason, I can not get the exit status of the ssh remote command. It does not matter if I give exit 0, or true or if I give a command that throws a success command, the end result is the same, I always get 1.



      The thing is, this code works perfectly when ran from a script, but not if I do it from a function.



      function hello(){
      while read user password
      do
      ssh -n -q user@host 'exit 0' ; echo $?
      done <<< "$( cat creds.txt )"
      }








      share














      So I have a function that looks like this. It's an oversimplified example but its enough to demonstrate my issue.



      For some reason, I can not get the exit status of the ssh remote command. It does not matter if I give exit 0, or true or if I give a command that throws a success command, the end result is the same, I always get 1.



      The thing is, this code works perfectly when ran from a script, but not if I do it from a function.



      function hello(){
      while read user password
      do
      ssh -n -q user@host 'exit 0' ; echo $?
      done <<< "$( cat creds.txt )"
      }






      ssh bash





      share












      share










      share



      share










      asked 8 mins ago









      Matias BarriosMatias Barrios

      1327




      1327






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "2"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fserverfault.com%2fquestions%2f957453%2fssh-exit-code-not-working-within-function%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Server Fault!


          • 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%2fserverfault.com%2fquestions%2f957453%2fssh-exit-code-not-working-within-function%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

          117736 Шеррод Примітки | Див. також | Посилання | Навігаційне...

          As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

          Маріан Котлеба Зміст Життєпис | Політичні погляди |...