Expect script works on CLI, but not under Nagios


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect script works on CLI, but not under Nagios
# 1  
Old 04-23-2013
Linux 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:
Code:
    # 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):
Code:
    -----------------------
    # 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!
# 2  
Old 07-10-2013
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 Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Expect scripting issue, works interactively when doing commands in cli, does not work in script

Hi; problem may be obvious, simple but I have to say it is somehow not easy to locate the issue. I am doing some word extracting from multiline text. Interacting in CLI seems to work without issues. First step is to add multiline text to a variable. expect1.1> expect1.1> set... (2 Replies)
Discussion started by: aldowski
2 Replies

2. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

3. Shell Programming and Scripting

Controlling elinks from Pipe, CLI or Script

Hi guys, I’m looking for an automatic way to save the source code of an website to a file. My questions is, it is possible to control elinks from a script, pipe or cli? I need to open a website, login on this site by a webform, submit the form, open an new url and save the source code of a... (2 Replies)
Discussion started by: digg_de
2 Replies

4. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

5. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

6. Shell Programming and Scripting

Not the correct output, works fine via CLI, not inside the script.

Guys, I need you help please. The script below is not working correclty for checking via a awk/if statement . Can you tell me what i am doing wrong in the script code "if($1 == "$RETENTION_LEVEL") " Syntax RETENTION_LEVEL=`echo $LINE | cut -f2 -d" "` echo " ==============... (4 Replies)
Discussion started by: Junes
4 Replies

7. Shell Programming and Scripting

Reading CLI input for script

I've always written scripts where the user executes the script and I prompt them for what they want to do. But I'm trying to write a script where root executes the script 'lock' or its hard-link 'unlock' and the script will passwd -l or passwd -u an account depending on the choice. What would... (3 Replies)
Discussion started by: ADay2Long
3 Replies

8. Shell Programming and Scripting

simple php/expect script works from command line but not from web

I have a really basic expect script which I call from php. I works fine when I run the php from the shell, but from the web it appears as if the output buffer gets chopped and never gets all of the contents. php script: (runexpect.php) <?php... (7 Replies)
Discussion started by: jacksona2
7 Replies

9. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

10. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies
Login or Register to Ask a Question