Forum Discussion
OK, that helps explain the prompt thing. I was thinking it just needed to end # not that it was looking for the whole prompt. So I used https://www.regexpal.com/ to verify a correct prompt. I also typed through my cli.send while logged in as the LogicMonitor account.
*login*
terminal length 0
show running-config
exit
----------------------
When I exit the device the follow displays:
<host/user># exit
[screen is terminating]
Connection to <host> closed.
bash-4.3$
Not sure what cli.expect() I should use for the line following cli.send("exit\n")
---------------------My Current Script---------------------------
import com.santaba.agent.groovyapi.expect.Expect
host = hostProps.get("system.hostname");
user = hostProps.get("config.user");
pass = hostProps.get("config.pass");
prompt = /.+\#\s/
cli=Expect.open(host, user, pass); <----login
cli.expect(prompt); <----wait for prompt
cli.send("terminal length 0\n"); <----Set so show run shows all at one time
cli.expect(prompt); <----wait for prompt
cli.send("show running-config\n"); <------------ Changed from cli.send("show running-config all\n"); since show running-config all isn't a command
cli.expect(/Current configuration.*\n/); <--Guess this one is expecting the config (Currently with the terminal length 0 show run ends on the prompt)
cli.send("exit\n"); <---- Exit the device
cli.expect("[screen is terminating]"); <----- Not sure what to expect here
config=cli.before(); <------ Seems unnecessary (just change println config to println(cli.before()) )
config = config.replaceAll(/ntp clock-period \d+/,"ntp clock-period "); <--- Not sure
cli.expectClose();
println config;
------------------------------------------------------------------------
I've played with variations of the above script and tried /* commenting */ parts of it out with println(cli.before()) and/or println(cli.stdout()) added in different sections. Also tried ending it with return 0 and switching the config.user and config.pass to ssh.user and ssh.pass.
Still getting:
The script failed, elapsed time: 60 seconds - End of stream reached, no match found java.io.IOException: End of stream reached, no match found
Earlier in the day I also sometimes got a different error, but now I cannot get the error to come up again. It Was something about timing out after 47 seconds.
Related Content
- 2 months ago
- 2 years ago
- 2 years ago