program output accumulating in expect_out(buf

Help
Jeff Boyer
2008-08-07
2013-05-02
  • Jeff Boyer
    Jeff Boyer
    2008-08-07

    Hi,

    HELP...The script I inherited some years ago performs a client-server service for a program so it can support multiple platforms. It uses a send to run a script that runs a program on the server via an xterm. Here's the portion of the script:

    send -i $ssh_id "$runfile\r"
    expect {
        timeout      {
            feedback "\n##### ERROR (main): SSH timed out waiting to run remote script $runfile #####"
            sleep 20; exit
        }
        "directory"  {
            feedback "\n##### ERROR (main): Unable to execute remote script: $runfile #####"
            sleep 20; exit
        }
        "command not found" {
            feedback "\n##### ERROR (main): Unable to execute remote script: $runfile. File Not Found. #####"
            sleep 20; exit
        }
        "Remote Run Complete!" {
            feedback "\n##### NOTICE (main): Full PDT remote script run completed #####"
            set timeout 2
            expect {
                timeout {
                        feedback "\n##### ERROR (main): Full PDT run timed out waiting for prompt $ssh_prompt. #####"
                }
                -re $ssh_prompt
            }
        }
        -re $ssh_prompt {
            feedback "\n##### ERROR (main): Houston...looks like we have a problem!..."
            feedback "        Fetching files in 30 seconds..review remote logfiles for more info... #####"
            sleep 30
        }

    }

    Something has recently changed because the script now always outputs the ERROR. Using the diagnostic option, I see that what is multi-line output to the xterm is accumulating in the buffer; e.g.:

    expect: does "pdt_Run_17/run_PDTserver\r\nxyz3:XYZ /home/xyz/XYZ/rPDT_D13.2-RHEL4-JSBlocal 103> Copyright 2008, California Institute of Technology\r\n\r\n\r\n\r\n\r\n***************************************************************\r\n*****
    Beginning Remote Run pdt_Run_17: ITARGET_Run...\r\n" (spawn_id exp21) match glob pattern "Remote Run Complete!"? no

    The result is that the -re $ssh_prompt is being matched (nxyz3:XYZ /home/xyz/XYZ/rPDT_D13.2-RHEL4-JSBlocal 103>)...thus a false negative is reported when the program run is in fact OK.

    Is accumulation of the output to the xterm in the expect buffer the expected behavior?

    Thanks, Jeff

     
    • ender
      ender
      2008-10-29

      Is this still a problem for you?

      When looking at the diag option it will show you the buffer of input it is using to try and match your pattern. When it matches then it will no longer try to match the new expect pattern to what came before that. does "..." match ".." will keep accumulating terminal input until it matches.