expect: does “” (spawn_id exp70) match glob pattern

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have written an expect script that works perfect for testing passwords on our network until it has looped through my list quite a bit, then the debug output shows that there is nothing to match.



Here is some debug that shows the buffer with data in it, then the next spawn with no data:



ssh: connect to host 12.23.34.56 port 22: No route to host

expect: does "ssh: connect to host 12.23.34.56 port 22: No route to hostrrn" (spawn_id exp69) match glob pattern "(yes/no)? "? no
"assword: "? no
"]# "? no
"oute to host"? yes
expect: set expect_out(0,string) "oute to host"
expect: set expect_out(spawn_id) "exp69"
expect: set expect_out(buffer) "ssh: connect to host 12.23.34.56 port 22: No route to host"
spawn ssh -o PreferredAuthentications=password -o NumberOfPasswordPrompts=3 admin@x.x.x.x
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns 26418

expect: does "" (spawn_id exp70) match glob pattern "(yes/no)? "? no
"assword: "? no
"]# "? no
"oute to host"? no
"onnection refused"? no
"isconnected from"? no
expect: timed out


Every spawn_id after exp69 has nothing in the does "" match section.



I think this is related to the buffer some how, but I've tried:



match_max 200000
match_max 600000


And this didn't seem to make any difference. I've removed the real ips and changed it to x.x.x.x. I"m not actually testing x.x.x.x (but the 12.23.34.56 did slip into my list of servers to check)



The script itself is running expect and loops over another file called "servers.txt" and tries line by line to execute a series of commands on that server. It logs what worked and what didn't. Here is what is in the script:



#!/usr/bin/expect

# where to log info, open "writable", this is our homegrown log
# unlike the others that follow
set logfile [open "passcheck-results" "w"]

# clobber and log
log_file -noappend passcheck-logfile

# disable user viewing of process as it happens
# 1=on, 0=off
# disables screen output only, recommended 0
log_user 1

# enable verbose debugging, from expect
# 1=on, 0=off
# useful for debugging the script itself, recommended: 0
exp_internal -f debug.log 0

# default waits for 10s, and if no response, kills process
# too low and machines may not respond fast enough
# in particular real timeouts are not registered if too low
# set to -1 for infinite, real timeouts can take 60s or more
# instead of waiting 60s for EVERY failure, set this lower
# recommend the 10s default
set timeout 10


# if you do not get all the response, you expect, increase buffer
match_max 600000

# get by argv functions instead
# set nohistory save on CLI/bash
set passwords password1 password2 password3

# open the list of servers to process
# warning, no error checking on file open
set input [open "servers.txt" "r"]

# loop over the list of servers with prompt logic
foreach ip [split [read $input] "n"]


# slowing it down a bit
sleep 2

# had to change =password to get results I wanted
# loop over line of servers
spawn ssh -o PreferredAuthentications=password
-o NumberOfPasswordPrompts=[llength $passwords] admin@$ip

# verify where exactly to reset this count
set try 0

# account for other possibilities
expect
"(yes/no)? "
# new host detected
sleep 1
send "yesr"
exp_continue

"assword: "
if $try >= [llength $passwords]
puts $logfile "Bad_Passwords $ip"
#send_error ">>> wrong passwordsn"
exit 1

sleep 1
send [lindex $passwords $try]r
incr try
exp_continue

"]# "
puts $logfile "succeeded_$try $ip"
sleep 1
send "exitr"

"oute to host"
puts $logfile "No_Route_to_Host $ip"

"onnection refused"
puts $logfile "Refused $ip"

"isconnected from"
puts $logfile "Disconnected $ip"

timeout
puts $logfile "timed_out_or_fail $ip"












share|improve this question















migrated from serverfault.com Jun 13 '15 at 11:04


This question came from our site for system and network administrators.


















    up vote
    0
    down vote

    favorite












    I have written an expect script that works perfect for testing passwords on our network until it has looped through my list quite a bit, then the debug output shows that there is nothing to match.



    Here is some debug that shows the buffer with data in it, then the next spawn with no data:



    ssh: connect to host 12.23.34.56 port 22: No route to host

    expect: does "ssh: connect to host 12.23.34.56 port 22: No route to hostrrn" (spawn_id exp69) match glob pattern "(yes/no)? "? no
    "assword: "? no
    "]# "? no
    "oute to host"? yes
    expect: set expect_out(0,string) "oute to host"
    expect: set expect_out(spawn_id) "exp69"
    expect: set expect_out(buffer) "ssh: connect to host 12.23.34.56 port 22: No route to host"
    spawn ssh -o PreferredAuthentications=password -o NumberOfPasswordPrompts=3 admin@x.x.x.x
    parent: waiting for sync byte
    parent: telling child to go ahead
    parent: now unsynchronized from child
    spawn: returns 26418

    expect: does "" (spawn_id exp70) match glob pattern "(yes/no)? "? no
    "assword: "? no
    "]# "? no
    "oute to host"? no
    "onnection refused"? no
    "isconnected from"? no
    expect: timed out


    Every spawn_id after exp69 has nothing in the does "" match section.



    I think this is related to the buffer some how, but I've tried:



    match_max 200000
    match_max 600000


    And this didn't seem to make any difference. I've removed the real ips and changed it to x.x.x.x. I"m not actually testing x.x.x.x (but the 12.23.34.56 did slip into my list of servers to check)



    The script itself is running expect and loops over another file called "servers.txt" and tries line by line to execute a series of commands on that server. It logs what worked and what didn't. Here is what is in the script:



    #!/usr/bin/expect

    # where to log info, open "writable", this is our homegrown log
    # unlike the others that follow
    set logfile [open "passcheck-results" "w"]

    # clobber and log
    log_file -noappend passcheck-logfile

    # disable user viewing of process as it happens
    # 1=on, 0=off
    # disables screen output only, recommended 0
    log_user 1

    # enable verbose debugging, from expect
    # 1=on, 0=off
    # useful for debugging the script itself, recommended: 0
    exp_internal -f debug.log 0

    # default waits for 10s, and if no response, kills process
    # too low and machines may not respond fast enough
    # in particular real timeouts are not registered if too low
    # set to -1 for infinite, real timeouts can take 60s or more
    # instead of waiting 60s for EVERY failure, set this lower
    # recommend the 10s default
    set timeout 10


    # if you do not get all the response, you expect, increase buffer
    match_max 600000

    # get by argv functions instead
    # set nohistory save on CLI/bash
    set passwords password1 password2 password3

    # open the list of servers to process
    # warning, no error checking on file open
    set input [open "servers.txt" "r"]

    # loop over the list of servers with prompt logic
    foreach ip [split [read $input] "n"]


    # slowing it down a bit
    sleep 2

    # had to change =password to get results I wanted
    # loop over line of servers
    spawn ssh -o PreferredAuthentications=password
    -o NumberOfPasswordPrompts=[llength $passwords] admin@$ip

    # verify where exactly to reset this count
    set try 0

    # account for other possibilities
    expect
    "(yes/no)? "
    # new host detected
    sleep 1
    send "yesr"
    exp_continue

    "assword: "
    if $try >= [llength $passwords]
    puts $logfile "Bad_Passwords $ip"
    #send_error ">>> wrong passwordsn"
    exit 1

    sleep 1
    send [lindex $passwords $try]r
    incr try
    exp_continue

    "]# "
    puts $logfile "succeeded_$try $ip"
    sleep 1
    send "exitr"

    "oute to host"
    puts $logfile "No_Route_to_Host $ip"

    "onnection refused"
    puts $logfile "Refused $ip"

    "isconnected from"
    puts $logfile "Disconnected $ip"

    timeout
    puts $logfile "timed_out_or_fail $ip"












    share|improve this question















    migrated from serverfault.com Jun 13 '15 at 11:04


    This question came from our site for system and network administrators.
















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have written an expect script that works perfect for testing passwords on our network until it has looped through my list quite a bit, then the debug output shows that there is nothing to match.



      Here is some debug that shows the buffer with data in it, then the next spawn with no data:



      ssh: connect to host 12.23.34.56 port 22: No route to host

      expect: does "ssh: connect to host 12.23.34.56 port 22: No route to hostrrn" (spawn_id exp69) match glob pattern "(yes/no)? "? no
      "assword: "? no
      "]# "? no
      "oute to host"? yes
      expect: set expect_out(0,string) "oute to host"
      expect: set expect_out(spawn_id) "exp69"
      expect: set expect_out(buffer) "ssh: connect to host 12.23.34.56 port 22: No route to host"
      spawn ssh -o PreferredAuthentications=password -o NumberOfPasswordPrompts=3 admin@x.x.x.x
      parent: waiting for sync byte
      parent: telling child to go ahead
      parent: now unsynchronized from child
      spawn: returns 26418

      expect: does "" (spawn_id exp70) match glob pattern "(yes/no)? "? no
      "assword: "? no
      "]# "? no
      "oute to host"? no
      "onnection refused"? no
      "isconnected from"? no
      expect: timed out


      Every spawn_id after exp69 has nothing in the does "" match section.



      I think this is related to the buffer some how, but I've tried:



      match_max 200000
      match_max 600000


      And this didn't seem to make any difference. I've removed the real ips and changed it to x.x.x.x. I"m not actually testing x.x.x.x (but the 12.23.34.56 did slip into my list of servers to check)



      The script itself is running expect and loops over another file called "servers.txt" and tries line by line to execute a series of commands on that server. It logs what worked and what didn't. Here is what is in the script:



      #!/usr/bin/expect

      # where to log info, open "writable", this is our homegrown log
      # unlike the others that follow
      set logfile [open "passcheck-results" "w"]

      # clobber and log
      log_file -noappend passcheck-logfile

      # disable user viewing of process as it happens
      # 1=on, 0=off
      # disables screen output only, recommended 0
      log_user 1

      # enable verbose debugging, from expect
      # 1=on, 0=off
      # useful for debugging the script itself, recommended: 0
      exp_internal -f debug.log 0

      # default waits for 10s, and if no response, kills process
      # too low and machines may not respond fast enough
      # in particular real timeouts are not registered if too low
      # set to -1 for infinite, real timeouts can take 60s or more
      # instead of waiting 60s for EVERY failure, set this lower
      # recommend the 10s default
      set timeout 10


      # if you do not get all the response, you expect, increase buffer
      match_max 600000

      # get by argv functions instead
      # set nohistory save on CLI/bash
      set passwords password1 password2 password3

      # open the list of servers to process
      # warning, no error checking on file open
      set input [open "servers.txt" "r"]

      # loop over the list of servers with prompt logic
      foreach ip [split [read $input] "n"]


      # slowing it down a bit
      sleep 2

      # had to change =password to get results I wanted
      # loop over line of servers
      spawn ssh -o PreferredAuthentications=password
      -o NumberOfPasswordPrompts=[llength $passwords] admin@$ip

      # verify where exactly to reset this count
      set try 0

      # account for other possibilities
      expect
      "(yes/no)? "
      # new host detected
      sleep 1
      send "yesr"
      exp_continue

      "assword: "
      if $try >= [llength $passwords]
      puts $logfile "Bad_Passwords $ip"
      #send_error ">>> wrong passwordsn"
      exit 1

      sleep 1
      send [lindex $passwords $try]r
      incr try
      exp_continue

      "]# "
      puts $logfile "succeeded_$try $ip"
      sleep 1
      send "exitr"

      "oute to host"
      puts $logfile "No_Route_to_Host $ip"

      "onnection refused"
      puts $logfile "Refused $ip"

      "isconnected from"
      puts $logfile "Disconnected $ip"

      timeout
      puts $logfile "timed_out_or_fail $ip"












      share|improve this question















      I have written an expect script that works perfect for testing passwords on our network until it has looped through my list quite a bit, then the debug output shows that there is nothing to match.



      Here is some debug that shows the buffer with data in it, then the next spawn with no data:



      ssh: connect to host 12.23.34.56 port 22: No route to host

      expect: does "ssh: connect to host 12.23.34.56 port 22: No route to hostrrn" (spawn_id exp69) match glob pattern "(yes/no)? "? no
      "assword: "? no
      "]# "? no
      "oute to host"? yes
      expect: set expect_out(0,string) "oute to host"
      expect: set expect_out(spawn_id) "exp69"
      expect: set expect_out(buffer) "ssh: connect to host 12.23.34.56 port 22: No route to host"
      spawn ssh -o PreferredAuthentications=password -o NumberOfPasswordPrompts=3 admin@x.x.x.x
      parent: waiting for sync byte
      parent: telling child to go ahead
      parent: now unsynchronized from child
      spawn: returns 26418

      expect: does "" (spawn_id exp70) match glob pattern "(yes/no)? "? no
      "assword: "? no
      "]# "? no
      "oute to host"? no
      "onnection refused"? no
      "isconnected from"? no
      expect: timed out


      Every spawn_id after exp69 has nothing in the does "" match section.



      I think this is related to the buffer some how, but I've tried:



      match_max 200000
      match_max 600000


      And this didn't seem to make any difference. I've removed the real ips and changed it to x.x.x.x. I"m not actually testing x.x.x.x (but the 12.23.34.56 did slip into my list of servers to check)



      The script itself is running expect and loops over another file called "servers.txt" and tries line by line to execute a series of commands on that server. It logs what worked and what didn't. Here is what is in the script:



      #!/usr/bin/expect

      # where to log info, open "writable", this is our homegrown log
      # unlike the others that follow
      set logfile [open "passcheck-results" "w"]

      # clobber and log
      log_file -noappend passcheck-logfile

      # disable user viewing of process as it happens
      # 1=on, 0=off
      # disables screen output only, recommended 0
      log_user 1

      # enable verbose debugging, from expect
      # 1=on, 0=off
      # useful for debugging the script itself, recommended: 0
      exp_internal -f debug.log 0

      # default waits for 10s, and if no response, kills process
      # too low and machines may not respond fast enough
      # in particular real timeouts are not registered if too low
      # set to -1 for infinite, real timeouts can take 60s or more
      # instead of waiting 60s for EVERY failure, set this lower
      # recommend the 10s default
      set timeout 10


      # if you do not get all the response, you expect, increase buffer
      match_max 600000

      # get by argv functions instead
      # set nohistory save on CLI/bash
      set passwords password1 password2 password3

      # open the list of servers to process
      # warning, no error checking on file open
      set input [open "servers.txt" "r"]

      # loop over the list of servers with prompt logic
      foreach ip [split [read $input] "n"]


      # slowing it down a bit
      sleep 2

      # had to change =password to get results I wanted
      # loop over line of servers
      spawn ssh -o PreferredAuthentications=password
      -o NumberOfPasswordPrompts=[llength $passwords] admin@$ip

      # verify where exactly to reset this count
      set try 0

      # account for other possibilities
      expect
      "(yes/no)? "
      # new host detected
      sleep 1
      send "yesr"
      exp_continue

      "assword: "
      if $try >= [llength $passwords]
      puts $logfile "Bad_Passwords $ip"
      #send_error ">>> wrong passwordsn"
      exit 1

      sleep 1
      send [lindex $passwords $try]r
      incr try
      exp_continue

      "]# "
      puts $logfile "succeeded_$try $ip"
      sleep 1
      send "exitr"

      "oute to host"
      puts $logfile "No_Route_to_Host $ip"

      "onnection refused"
      puts $logfile "Refused $ip"

      "isconnected from"
      puts $logfile "Disconnected $ip"

      timeout
      puts $logfile "timed_out_or_fail $ip"









      linux ssh bash shell-script expect






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 26 at 0:30









      Rui F Ribeiro

      38.3k1477127




      38.3k1477127










      asked Jun 11 '15 at 16:24







      James











      migrated from serverfault.com Jun 13 '15 at 11:04


      This question came from our site for system and network administrators.






      migrated from serverfault.com Jun 13 '15 at 11:04


      This question came from our site for system and network administrators.






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          You may be running out of file descriptors. You probably need to call close
          on each spawn so you dont run out of resources.






          share|improve this answer



























            up vote
            0
            down vote













            You were correct, exp_internal -f passcheck-debug.log 1 pointed me to the problem of not having enough ptys. I added:



            close -i $spawn_id
            wait -nowait


            and it continued beyond that point. I had to add -nowait because if it doesn't have a spawn_id it will wait forever.






            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: 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%2f209409%2fexpect-does-spawn-id-exp70-match-glob-pattern%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








              up vote
              0
              down vote













              You may be running out of file descriptors. You probably need to call close
              on each spawn so you dont run out of resources.






              share|improve this answer
























                up vote
                0
                down vote













                You may be running out of file descriptors. You probably need to call close
                on each spawn so you dont run out of resources.






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You may be running out of file descriptors. You probably need to call close
                  on each spawn so you dont run out of resources.






                  share|improve this answer












                  You may be running out of file descriptors. You probably need to call close
                  on each spawn so you dont run out of resources.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 13 '15 at 18:26









                  meuh

                  31.1k11754




                  31.1k11754






















                      up vote
                      0
                      down vote













                      You were correct, exp_internal -f passcheck-debug.log 1 pointed me to the problem of not having enough ptys. I added:



                      close -i $spawn_id
                      wait -nowait


                      and it continued beyond that point. I had to add -nowait because if it doesn't have a spawn_id it will wait forever.






                      share|improve this answer
























                        up vote
                        0
                        down vote













                        You were correct, exp_internal -f passcheck-debug.log 1 pointed me to the problem of not having enough ptys. I added:



                        close -i $spawn_id
                        wait -nowait


                        and it continued beyond that point. I had to add -nowait because if it doesn't have a spawn_id it will wait forever.






                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          You were correct, exp_internal -f passcheck-debug.log 1 pointed me to the problem of not having enough ptys. I added:



                          close -i $spawn_id
                          wait -nowait


                          and it continued beyond that point. I had to add -nowait because if it doesn't have a spawn_id it will wait forever.






                          share|improve this answer












                          You were correct, exp_internal -f passcheck-debug.log 1 pointed me to the problem of not having enough ptys. I added:



                          close -i $spawn_id
                          wait -nowait


                          and it continued beyond that point. I had to add -nowait because if it doesn't have a spawn_id it will wait forever.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 30 '15 at 19:21









                          James

                          1




                          1



























                              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.





                              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%2funix.stackexchange.com%2fquestions%2f209409%2fexpect-does-spawn-id-exp70-match-glob-pattern%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

                              Peggy Mitchell

                              Palaiologos

                              The Forum (Inglewood, California)