sending commands to a mikrouter router

31 views
Skip to first unread message

ab...@aalejandro.com

unread,
Jun 3, 2018, 7:23:42 PM6/3/18
to Yet another Expect for Java
I have this code running but it seems its sending the next commands without waiting, even thou I am using expect to wait for the command prompt, is there anything else I can try?

Code:

Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
Channel channel = session.openChannel("shell");
channel.connect();

Expect expect = new ExpectBuilder()
.withOutput(channel.getOutputStream())
.withInputs(channel.getInputStream())
.withEchoInput(System.out)
.withEchoOutput(System.err)
//.withInputFilters(removeColors(), removeNonPrintable())
.withExceptionOnFailure()
//.withLineSeparator("\r")
.build();
try {
expect.expect(regexp("@.*] >"));
expect.sendLine("/ip dhcp-client set use-peer-dns=no numbers=0");
expect.expect(regexp("@.*] >"));
expect.sendLine("/ip dns set servers=8.8.8.8,1.1.1.1");
expect.expect(regexp("@.*] >"));
expect.sendLine("/ip dns set allow-remote-requests=no");
expect.expect(regexp("@.*] >"));
expect.sendLine("/ip proxy set enabled=no");
expect.expect(regexp("@.*] >"));
expect.sendLine("/system clock set time-zone-autodetect=no time-zone-name=America/Puerto_Rico");
expect.expect(regexp("@.*] >"));
expect.sendLine("/system ntp client set enabled=yes primary-ntp=74.85.156.1 secondary-ntp=74.85.156.2");
expect.expect(regexp("@.*] >"));
expect.sendLine("/snmp community set [ find default=yes ] name=4ll13d");
expect.expect(regexp("@.*] >"));
expect.sendLine("/snmp set contact=Fusetelecom");
expect.expect(regexp("@.*] >"));
} finally {
expect.close();
channel.disconnect();
session.disconnect();
}

Alexey Gavrilov

unread,
Jun 7, 2018, 2:19:54 AM6/7/18
to ab...@aalejandro.com, Yet another Expect for Java
Make sure you command expression matches only command line prompt. ‘]’ char may need to be escaped.
> --
> You received this message because you are subscribed to the Google Groups "Yet another Expect for Java" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to java-expecti...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages