Expect script works on CLI, but not under Nagios

I'm having a problem scripting Expect to work as a Nagios check. The script runs fine from the cli, but not when run as a Nagios check. I turn on the debug output, and it looks like it's not seeing the whole buffer's worth of info, like it's paged interactively somehow. I'm new to Expect, but this is confusing to me as it seems like an internal issue.

So my script spawns an ssh session, logs in twice (enable mode), then issues a command that validates user authentication and then logs out cleanly. At least, this is what it does from the command line. That same script when run directly via Nagios doesn't, and hangs at the userauth validation. I'm stumped.

Here's the section that errors:

    # other commands got us to this point...
    exp_internal -f /tmp/expect_diags 1
    send "aaa test-server mschapv2 tester account1 password1\r"
    
    # at next line, nagios run times out; command line runs fine
    expect -timeout 9 "Successful"
    # printout some debugs to logs whether it works or times out
    send_log "log 0: $expect_out(0,string)\n"
    send_log "log x: $expect_out(buffer)\n"
    
    #---stock exit here so I can see some output; adjust later after above fixed----
    set TIME [exec date +%H:%M:%S]
    send_user "Time: $TIME\n"
    send_log "-----------------------\n"
    exit 0

And here's the outputs to the log file when run from cli (top) and under Nagios (bottom):

    -----------------------
    # Note: this is the debug output from the cli, which sees the string
    send: sending "aaa test-server mschapv2 tester account1 password1\r" to { exp6 }
    
    expect: does "" (spawn_id exp6) match glob pattern "Successful"? no
    aaa test-server mschapv2 tester account1 password1
    expect: does "aaa test-server mschapv2 tester account1 password1" (spawn_id exp6) match glob pattern "Successful"? no
    
    
    Authentication Successful
    
    (Aruba3400) #
    expect: does "aaa test-server mschapv2 tester account1 password1\r\n\r\nAuthentication Successful\r\n\r\n(Aruba3400) #" (spawn_id exp6) match glob pattern "Successful"? yes
    expect: set expect_out(0,string) "Successful"
    expect: set expect_out(spawn_id) "exp6"
    expect: set expect_out(buffer) "aaa test-server mschapv2 tester account1 password1\r\n\r\nAuthentication Successful"
    Time: 16:17:05
    -----------------------
    # Note: this is the debug output when run under Nagios, which doesn't
    send: sending "aaa test-server mschapv2 tester sgates2 stealth\r" to { exp5 }
    
    expect: does "" (spawn_id exp5) match glob pattern "Successful"? no
    aaa test-server mschapv2 d-t
    expect: does "aaa test-server mschapv2 tes" (spawn_id exp5) match glob pattern "Successful"? no
    te
    expect: does "aaa test-server mschapv2 teste" (spawn_id exp5) match glob pattern "Successful"? no
    r accoun
    expect: does "aaa test-server mschapv2 tester accoun" (spawn_id exp5) match glob pattern "Successful"? no
    t1
    expect: does "aaa test-server mschapv2 tester account1" (spawn_id exp5) match glob pattern "Successful"? no
     pass
    expect: does "aaa test-server mschapv2 tester account1 pass" (spawn_id exp5) match glob pattern "Successful"? no
    wor
    expect: does "aaa test-server mschapv2 tester account1 password1" (spawn_id exp5) match glob pattern "Successful"? no
    --More-- (q) quit (u) pageup (/) search (n) repeat
    expect: does "aaa test-server mschapv2 tester account1 password1--More-- (q) quit (u) pageup (/) search (n) repeat" (spawn_id exp5) match glob pattern "Successful"? no
    expect: timed out
    Time: 16:17:32
    -----------------------

ANY help on this would be greatly appreciated. I don't understand what's going on, and why when run by Nagios it appears to be paging the results like it's an interactive session.
Thanks in advance!

Hi Guys,
I need a help in nagios notifications setup.
I have a script that will generate alert for w and critical based on a condition.
What I want is that "Nagios should send out an alert for warning only if the condition i.e. written in the script exists for more than an 1hr then. No change is required for critical."
Please help me on this :frowning: