Command puts in expect doesn't show the message in the order it should












0















I have a some scripts to automate a process and I want the message about which step I am in it shows in the command window. A piece of code I have is:



puts "** Creation of $VMNAME on $HOST begins... **"
spawn ssh -l $USER $HOST
expect_after eof {exit 0}
set timeout 10

expect "(yes/no)?" { send "yesr" }
expect "password:" { send "$PASSWORDr" }
expect "~]#" { send "dater" }
set timeout 1200

puts "** Transferring rhelvm img file to the $HOST... **"
expect "~]#" { send "scp somelink/rhelvm-0-vol.img /storage/iso/r" }
expect "Password:" { send "$TESTEMSPASSr" }

puts "** Transferring the VM conf from $TESTEMSUSER to $HOST... **"
expect "~]#" { send "scp somelink/$VMNAME.conf /rootr" }
expect "Password:" { send "$TESTEMSPASSr" }

puts "** Removing the $VMNAME... **"
expect "~]#" { send "/opt/ccm/bin/vmremove -f /root/$VMNAME.conf --forcer" }
sleep 10
expect "~]#" { send "rm -rf /storage/vmpool/*.imgr" }
sleep 10

puts "** Creating the $VMNAME... **"
expect "~]#" { send "/opt/ccm/bin/vmcreate -f /root/$VMNAME.conf -g /storage/iso/rhelvm-0-vol.img -er" }
sleep 10

puts "** Starting the $VMNAME ... **"
expect "~]#" { send "virsh start $VMNAMEr" }
sleep 10

expect "~]#" { send "virsh list --allr"}

expect "~]#" { send "dater" }

puts "** Creation of $VMNAME is completed. **"
expect "~]#" { send "exitr" }


but what I get in the output is not in this order for example it shows the message of creating the VM but then runs the rm -rf /storage/vmpool/*.img command.
I tried puts with -nonewline and send_user but nothing seems to work. Please help me!!










share|improve this question














bumped to the homepage by Community 6 mins ago


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




















    0















    I have a some scripts to automate a process and I want the message about which step I am in it shows in the command window. A piece of code I have is:



    puts "** Creation of $VMNAME on $HOST begins... **"
    spawn ssh -l $USER $HOST
    expect_after eof {exit 0}
    set timeout 10

    expect "(yes/no)?" { send "yesr" }
    expect "password:" { send "$PASSWORDr" }
    expect "~]#" { send "dater" }
    set timeout 1200

    puts "** Transferring rhelvm img file to the $HOST... **"
    expect "~]#" { send "scp somelink/rhelvm-0-vol.img /storage/iso/r" }
    expect "Password:" { send "$TESTEMSPASSr" }

    puts "** Transferring the VM conf from $TESTEMSUSER to $HOST... **"
    expect "~]#" { send "scp somelink/$VMNAME.conf /rootr" }
    expect "Password:" { send "$TESTEMSPASSr" }

    puts "** Removing the $VMNAME... **"
    expect "~]#" { send "/opt/ccm/bin/vmremove -f /root/$VMNAME.conf --forcer" }
    sleep 10
    expect "~]#" { send "rm -rf /storage/vmpool/*.imgr" }
    sleep 10

    puts "** Creating the $VMNAME... **"
    expect "~]#" { send "/opt/ccm/bin/vmcreate -f /root/$VMNAME.conf -g /storage/iso/rhelvm-0-vol.img -er" }
    sleep 10

    puts "** Starting the $VMNAME ... **"
    expect "~]#" { send "virsh start $VMNAMEr" }
    sleep 10

    expect "~]#" { send "virsh list --allr"}

    expect "~]#" { send "dater" }

    puts "** Creation of $VMNAME is completed. **"
    expect "~]#" { send "exitr" }


    but what I get in the output is not in this order for example it shows the message of creating the VM but then runs the rm -rf /storage/vmpool/*.img command.
    I tried puts with -nonewline and send_user but nothing seems to work. Please help me!!










    share|improve this question














    bumped to the homepage by Community 6 mins ago


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


















      0












      0








      0








      I have a some scripts to automate a process and I want the message about which step I am in it shows in the command window. A piece of code I have is:



      puts "** Creation of $VMNAME on $HOST begins... **"
      spawn ssh -l $USER $HOST
      expect_after eof {exit 0}
      set timeout 10

      expect "(yes/no)?" { send "yesr" }
      expect "password:" { send "$PASSWORDr" }
      expect "~]#" { send "dater" }
      set timeout 1200

      puts "** Transferring rhelvm img file to the $HOST... **"
      expect "~]#" { send "scp somelink/rhelvm-0-vol.img /storage/iso/r" }
      expect "Password:" { send "$TESTEMSPASSr" }

      puts "** Transferring the VM conf from $TESTEMSUSER to $HOST... **"
      expect "~]#" { send "scp somelink/$VMNAME.conf /rootr" }
      expect "Password:" { send "$TESTEMSPASSr" }

      puts "** Removing the $VMNAME... **"
      expect "~]#" { send "/opt/ccm/bin/vmremove -f /root/$VMNAME.conf --forcer" }
      sleep 10
      expect "~]#" { send "rm -rf /storage/vmpool/*.imgr" }
      sleep 10

      puts "** Creating the $VMNAME... **"
      expect "~]#" { send "/opt/ccm/bin/vmcreate -f /root/$VMNAME.conf -g /storage/iso/rhelvm-0-vol.img -er" }
      sleep 10

      puts "** Starting the $VMNAME ... **"
      expect "~]#" { send "virsh start $VMNAMEr" }
      sleep 10

      expect "~]#" { send "virsh list --allr"}

      expect "~]#" { send "dater" }

      puts "** Creation of $VMNAME is completed. **"
      expect "~]#" { send "exitr" }


      but what I get in the output is not in this order for example it shows the message of creating the VM but then runs the rm -rf /storage/vmpool/*.img command.
      I tried puts with -nonewline and send_user but nothing seems to work. Please help me!!










      share|improve this question














      I have a some scripts to automate a process and I want the message about which step I am in it shows in the command window. A piece of code I have is:



      puts "** Creation of $VMNAME on $HOST begins... **"
      spawn ssh -l $USER $HOST
      expect_after eof {exit 0}
      set timeout 10

      expect "(yes/no)?" { send "yesr" }
      expect "password:" { send "$PASSWORDr" }
      expect "~]#" { send "dater" }
      set timeout 1200

      puts "** Transferring rhelvm img file to the $HOST... **"
      expect "~]#" { send "scp somelink/rhelvm-0-vol.img /storage/iso/r" }
      expect "Password:" { send "$TESTEMSPASSr" }

      puts "** Transferring the VM conf from $TESTEMSUSER to $HOST... **"
      expect "~]#" { send "scp somelink/$VMNAME.conf /rootr" }
      expect "Password:" { send "$TESTEMSPASSr" }

      puts "** Removing the $VMNAME... **"
      expect "~]#" { send "/opt/ccm/bin/vmremove -f /root/$VMNAME.conf --forcer" }
      sleep 10
      expect "~]#" { send "rm -rf /storage/vmpool/*.imgr" }
      sleep 10

      puts "** Creating the $VMNAME... **"
      expect "~]#" { send "/opt/ccm/bin/vmcreate -f /root/$VMNAME.conf -g /storage/iso/rhelvm-0-vol.img -er" }
      sleep 10

      puts "** Starting the $VMNAME ... **"
      expect "~]#" { send "virsh start $VMNAMEr" }
      sleep 10

      expect "~]#" { send "virsh list --allr"}

      expect "~]#" { send "dater" }

      puts "** Creation of $VMNAME is completed. **"
      expect "~]#" { send "exitr" }


      but what I get in the output is not in this order for example it shows the message of creating the VM but then runs the rm -rf /storage/vmpool/*.img command.
      I tried puts with -nonewline and send_user but nothing seems to work. Please help me!!







      linux scripting expect






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 6 '17 at 16:45









      BebeBebe

      1216




      1216





      bumped to the homepage by Community 6 mins 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 6 mins ago


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
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You may need to flush the output file. After each puts add the line



           flush stdout


          See the tcl flush command. Alternatively, you can set the output to non-buffered mode with a single line:



           fconfigure stdout -buffering none


          See tcl fconfigure.






          share|improve this answer


























          • I resolved the issue with including the puts in {} after expect and it worked. But I will look into your explanation also. thanks.

            – Bebe
            Mar 6 '17 at 18:30











          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%2f349532%2fcommand-puts-in-expect-doesnt-show-the-message-in-the-order-it-should%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









          0














          You may need to flush the output file. After each puts add the line



           flush stdout


          See the tcl flush command. Alternatively, you can set the output to non-buffered mode with a single line:



           fconfigure stdout -buffering none


          See tcl fconfigure.






          share|improve this answer


























          • I resolved the issue with including the puts in {} after expect and it worked. But I will look into your explanation also. thanks.

            – Bebe
            Mar 6 '17 at 18:30
















          0














          You may need to flush the output file. After each puts add the line



           flush stdout


          See the tcl flush command. Alternatively, you can set the output to non-buffered mode with a single line:



           fconfigure stdout -buffering none


          See tcl fconfigure.






          share|improve this answer


























          • I resolved the issue with including the puts in {} after expect and it worked. But I will look into your explanation also. thanks.

            – Bebe
            Mar 6 '17 at 18:30














          0












          0








          0







          You may need to flush the output file. After each puts add the line



           flush stdout


          See the tcl flush command. Alternatively, you can set the output to non-buffered mode with a single line:



           fconfigure stdout -buffering none


          See tcl fconfigure.






          share|improve this answer















          You may need to flush the output file. After each puts add the line



           flush stdout


          See the tcl flush command. Alternatively, you can set the output to non-buffered mode with a single line:



           fconfigure stdout -buffering none


          See tcl fconfigure.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 6 '17 at 17:28

























          answered Mar 6 '17 at 17:03









          meuhmeuh

          32.2k11954




          32.2k11954













          • I resolved the issue with including the puts in {} after expect and it worked. But I will look into your explanation also. thanks.

            – Bebe
            Mar 6 '17 at 18:30



















          • I resolved the issue with including the puts in {} after expect and it worked. But I will look into your explanation also. thanks.

            – Bebe
            Mar 6 '17 at 18:30

















          I resolved the issue with including the puts in {} after expect and it worked. But I will look into your explanation also. thanks.

          – Bebe
          Mar 6 '17 at 18:30





          I resolved the issue with including the puts in {} after expect and it worked. But I will look into your explanation also. thanks.

          – Bebe
          Mar 6 '17 at 18:30


















          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%2f349532%2fcommand-puts-in-expect-doesnt-show-the-message-in-the-order-it-should%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

          Loup dans la culture

          How to solve the problem of ntp “Unable to contact time server” from KDE?

          ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux