--
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.
Hope you are doing well. My schedule has gotten free for me and was hoping to take a look at this again. Please let me know if you are able to provide some examples of what I described above.
Alexey,
I understand and Christmas timeline is totally OK. I hope to take deeper dive into what your tool does as it is a critical piece in the application I will be writing. Looking forward to thorough documentation. If I can be of any help testing or whatever please reach out. I appreciate the level of effort you have provided. I’m hoping once I get some more java experience I can contribute to this development community as well.
I work at Verizon and anticipate using your tool heavily to preform network management tasks and automating our processes aligned with that activity.
Thanks again for your timely support.
On 14 Sep 2016, at 21:42, Thomas Campion <tc1...@gmail.com> wrote:here is Perl code, Im trying to do similar in java using expectit.
$exp-> spawn("ssh -l $username $device_ip\n");
$exp->expect(10, <- default timeout if no matches below found
[ qr/ssh -l $username $device_ip\r/ => sub { exp_continue; } ], <- regex match echoed command, continue matching
[ qr/\(yes\/no\)\?\s*$/ => sub { $exp->send("yes\n"); exp_continue; } ], <- regex match some devices ask a question before presenting login prompt answer and continue matching
[ qr/[Pp]assword:\s*$/ => sub { $exp->send("$password\n"); exp_continue;} ], <- regex match password prompt, send password, and continue matching
[ qr/User/ => sub { $exp->send("$username\n"); exp_continue;} ], <- regex username prompt, send username , and continue matching
[ qr/Login invalid/ => sub { $log .= 'bad un/pw';} ], <- regex bad credentials, log it and end expect matching
[ qr/Press any key to continue/ => sub { $exp->send("\n"); exp_continue;} ], <- regex match some devices ask a question before presenting login prompt answer and continue matching
[ qr/#/ => sub { $this_login_priv_mode = 'enable'; } ], <- got enable prompt good news end this expect move onto the next thing
[ qr/>$/ => sub {
$exp->send("en\n");
$exp->expect(10, -re, "[Pp]assword:"); <- regex see user mode prompt try getting to privileged mode, and continue expect matching
$exp->send("$password}\n");
exp_continue; } ],
[ qr/closed/ } ],
[ qr/Connection refused/} ],
[ qr/Permission denied/ } ], <- regex matching other fault conditions, discontinue matching
[ qr/Access denied/ } ],
[ timeout => } ],
);
final Result result = expect.interact()
.when(contains("yes/no")).then((r) -> expect.sendLine("yes"))
.when(contains("Press any key to continue")).then((r) -> expect.sendLine())
.when(regexp("[Pp]assword:\\s")).then((r) -> expect.sendLine("SECRET"))
.when(regexp("User")).then((r) -> expect.sendLine("USERNAME"))
.when(regexp(">$")).then((r) -> expect.sendLine("en"))
.until(
anyOf(
contains("#"),
contains("closed"),
contains("Login invalid"),
contains("Connection refused"),
contains("Permission denied"),
contains("Access denied")));
if ("#".equals(result.group())) {
System.out.println("this_login_priv_mode");
} else if ("Login invalid".equals(result.group())) {
System.out.println("bad un/pw");
}