How do I parse the remote server name inside echo when executing over ssh











up vote
0
down vote

favorite












I know the title is a bit confusing but there is no other way.



Script runs and connects to remote server over ssh. This is going to run on 500 servers thatswhy I 'd like to have an output like this on the console.



echo " checking $hostname" or echo " checking ${hostname}" returns nothing.
echo " checking $(hostname)" returns the hostname of the local server ironically.



ssh $Server /bin/bash <<EOF
install some software
echo "checking <remote-server-name> after installation"
java -version
groovy -v
jruby -v
EOF


I was just curious if this is doable actually.
Thanx in advance.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I know the title is a bit confusing but there is no other way.



    Script runs and connects to remote server over ssh. This is going to run on 500 servers thatswhy I 'd like to have an output like this on the console.



    echo " checking $hostname" or echo " checking ${hostname}" returns nothing.
    echo " checking $(hostname)" returns the hostname of the local server ironically.



    ssh $Server /bin/bash <<EOF
    install some software
    echo "checking <remote-server-name> after installation"
    java -version
    groovy -v
    jruby -v
    EOF


    I was just curious if this is doable actually.
    Thanx in advance.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I know the title is a bit confusing but there is no other way.



      Script runs and connects to remote server over ssh. This is going to run on 500 servers thatswhy I 'd like to have an output like this on the console.



      echo " checking $hostname" or echo " checking ${hostname}" returns nothing.
      echo " checking $(hostname)" returns the hostname of the local server ironically.



      ssh $Server /bin/bash <<EOF
      install some software
      echo "checking <remote-server-name> after installation"
      java -version
      groovy -v
      jruby -v
      EOF


      I was just curious if this is doable actually.
      Thanx in advance.










      share|improve this question















      I know the title is a bit confusing but there is no other way.



      Script runs and connects to remote server over ssh. This is going to run on 500 servers thatswhy I 'd like to have an output like this on the console.



      echo " checking $hostname" or echo " checking ${hostname}" returns nothing.
      echo " checking $(hostname)" returns the hostname of the local server ironically.



      ssh $Server /bin/bash <<EOF
      install some software
      echo "checking <remote-server-name> after installation"
      java -version
      groovy -v
      jruby -v
      EOF


      I was just curious if this is doable actually.
      Thanx in advance.







      ssh echo eof hostname






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 11:04

























      asked Nov 19 at 19:44









      DimiDak

      506410




      506410
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted











          echo " checking $hostname" or echo " checking ${hostname}" returns nothing.




          That is expected. There is in general no such variable named hostname, so you wouldn't expect a result. There is however a HOSTNAME variable, but that's only half the problem.




          echo " checking $(hostname)" returns the hostname of the local server ironically.




          That's because when you use "here" document, as in



          somecommand << EOF
          ...
          EOF


          The contents of the here document are evaluated for variable expansion before the input is fed to your command. This is exactly why the $(hostname) construct is executing the hostname command on your local system.



          You can inhibit the evaluation of the here document by quoting your end marker with single quotes, like this:



          ssh $Server /bin/bash <<'EOF'
          install some software
          echo "checking $HOSTNAME after installation"
          java -version
          groovy -v
          jruby -v
          EOF





          share|improve this answer





















          • Wow, great answer man, thanx. Not that I'm a Bash-Guru but I have the feeling that no matter how much you learn, bash remains a mystery... Cheers, Dimi
            – DimiDak
            Nov 20 at 15:34













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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%2fstackoverflow.com%2fquestions%2f53381614%2fhow-do-i-parse-the-remote-server-name-inside-echo-when-executing-over-ssh%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted











          echo " checking $hostname" or echo " checking ${hostname}" returns nothing.




          That is expected. There is in general no such variable named hostname, so you wouldn't expect a result. There is however a HOSTNAME variable, but that's only half the problem.




          echo " checking $(hostname)" returns the hostname of the local server ironically.




          That's because when you use "here" document, as in



          somecommand << EOF
          ...
          EOF


          The contents of the here document are evaluated for variable expansion before the input is fed to your command. This is exactly why the $(hostname) construct is executing the hostname command on your local system.



          You can inhibit the evaluation of the here document by quoting your end marker with single quotes, like this:



          ssh $Server /bin/bash <<'EOF'
          install some software
          echo "checking $HOSTNAME after installation"
          java -version
          groovy -v
          jruby -v
          EOF





          share|improve this answer





















          • Wow, great answer man, thanx. Not that I'm a Bash-Guru but I have the feeling that no matter how much you learn, bash remains a mystery... Cheers, Dimi
            – DimiDak
            Nov 20 at 15:34

















          up vote
          1
          down vote



          accepted











          echo " checking $hostname" or echo " checking ${hostname}" returns nothing.




          That is expected. There is in general no such variable named hostname, so you wouldn't expect a result. There is however a HOSTNAME variable, but that's only half the problem.




          echo " checking $(hostname)" returns the hostname of the local server ironically.




          That's because when you use "here" document, as in



          somecommand << EOF
          ...
          EOF


          The contents of the here document are evaluated for variable expansion before the input is fed to your command. This is exactly why the $(hostname) construct is executing the hostname command on your local system.



          You can inhibit the evaluation of the here document by quoting your end marker with single quotes, like this:



          ssh $Server /bin/bash <<'EOF'
          install some software
          echo "checking $HOSTNAME after installation"
          java -version
          groovy -v
          jruby -v
          EOF





          share|improve this answer





















          • Wow, great answer man, thanx. Not that I'm a Bash-Guru but I have the feeling that no matter how much you learn, bash remains a mystery... Cheers, Dimi
            – DimiDak
            Nov 20 at 15:34















          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted







          echo " checking $hostname" or echo " checking ${hostname}" returns nothing.




          That is expected. There is in general no such variable named hostname, so you wouldn't expect a result. There is however a HOSTNAME variable, but that's only half the problem.




          echo " checking $(hostname)" returns the hostname of the local server ironically.




          That's because when you use "here" document, as in



          somecommand << EOF
          ...
          EOF


          The contents of the here document are evaluated for variable expansion before the input is fed to your command. This is exactly why the $(hostname) construct is executing the hostname command on your local system.



          You can inhibit the evaluation of the here document by quoting your end marker with single quotes, like this:



          ssh $Server /bin/bash <<'EOF'
          install some software
          echo "checking $HOSTNAME after installation"
          java -version
          groovy -v
          jruby -v
          EOF





          share|improve this answer













          echo " checking $hostname" or echo " checking ${hostname}" returns nothing.




          That is expected. There is in general no such variable named hostname, so you wouldn't expect a result. There is however a HOSTNAME variable, but that's only half the problem.




          echo " checking $(hostname)" returns the hostname of the local server ironically.




          That's because when you use "here" document, as in



          somecommand << EOF
          ...
          EOF


          The contents of the here document are evaluated for variable expansion before the input is fed to your command. This is exactly why the $(hostname) construct is executing the hostname command on your local system.



          You can inhibit the evaluation of the here document by quoting your end marker with single quotes, like this:



          ssh $Server /bin/bash <<'EOF'
          install some software
          echo "checking $HOSTNAME after installation"
          java -version
          groovy -v
          jruby -v
          EOF






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 12:25









          larsks

          113k18184194




          113k18184194












          • Wow, great answer man, thanx. Not that I'm a Bash-Guru but I have the feeling that no matter how much you learn, bash remains a mystery... Cheers, Dimi
            – DimiDak
            Nov 20 at 15:34




















          • Wow, great answer man, thanx. Not that I'm a Bash-Guru but I have the feeling that no matter how much you learn, bash remains a mystery... Cheers, Dimi
            – DimiDak
            Nov 20 at 15:34


















          Wow, great answer man, thanx. Not that I'm a Bash-Guru but I have the feeling that no matter how much you learn, bash remains a mystery... Cheers, Dimi
          – DimiDak
          Nov 20 at 15:34






          Wow, great answer man, thanx. Not that I'm a Bash-Guru but I have the feeling that no matter how much you learn, bash remains a mystery... Cheers, Dimi
          – DimiDak
          Nov 20 at 15:34




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


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





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2fstackoverflow.com%2fquestions%2f53381614%2fhow-do-i-parse-the-remote-server-name-inside-echo-when-executing-over-ssh%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

          Paul Cézanne

          UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

          Angular material date-picker (MatDatepicker) auto completes the date on focus out