Forum Discussion
Final Product:
import com.santaba.agent.groovyapi.expect.Expect
host = hostProps.get("system.hostname");
user = hostProps.get("config.user");
pass = hostProps.get("config.pass");
display = hostProps.get("system.displayname");
/* Define prompt to work for HOSTNAME/USERname#
/ <-Start
${display} <- display defined earlier
\/ <- matches /
${user} <- user defined earlier
\# <- matches #
\s <- space
/ <-End
*/
prompt = /${display}\/${user}\#\s/
//Login and expect prompt
cli=Expect.open(host, user, pass);
cli.expect(prompt);
//Set terminal length to 0 so show run shows all at once then expect prompt
cli.send("terminal length 0\n");
cli.expect(prompt);
//show running-config then expect prompt then print everything before the above expect to the next above expect
//NOTE: The line show running-config will also be printed and can be ignored in a Config Check
cli.send("show running-config\n");
cli.expect(prompt);
println(cli.before());
//Exit device
cli.send("exit\n");
cli.expectClose();
Related Content
- 2 years ago
- 3 months ago
- 2 years ago