You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(1) |
Oct
(1) |
Nov
(26) |
Dec
(7) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(5) |
Feb
(3) |
Mar
(11) |
Apr
(10) |
May
(2) |
Jun
(5) |
Jul
(13) |
Aug
(2) |
Sep
(3) |
Oct
(10) |
Nov
(18) |
Dec
(29) |
2002 |
Jan
(12) |
Feb
(14) |
Mar
(73) |
Apr
(28) |
May
(21) |
Jun
(39) |
Jul
(40) |
Aug
(42) |
Sep
(20) |
Oct
(4) |
Nov
(9) |
Dec
(18) |
2003 |
Jan
(2) |
Feb
(8) |
Mar
(6) |
Apr
(24) |
May
(24) |
Jun
(14) |
Jul
(16) |
Aug
(36) |
Sep
(34) |
Oct
(23) |
Nov
(4) |
Dec
(15) |
2004 |
Jan
(6) |
Feb
(13) |
Mar
(7) |
Apr
(5) |
May
(11) |
Jun
(5) |
Jul
(4) |
Aug
|
Sep
(2) |
Oct
(16) |
Nov
(4) |
Dec
(9) |
2005 |
Jan
(2) |
Feb
(1) |
Mar
(3) |
Apr
(10) |
May
(5) |
Jun
(13) |
Jul
(3) |
Aug
|
Sep
(7) |
Oct
(5) |
Nov
(1) |
Dec
(9) |
2006 |
Jan
|
Feb
(10) |
Mar
(22) |
Apr
(14) |
May
(5) |
Jun
(4) |
Jul
(19) |
Aug
(7) |
Sep
(16) |
Oct
(4) |
Nov
(1) |
Dec
(16) |
2007 |
Jan
(17) |
Feb
|
Mar
(35) |
Apr
(5) |
May
(20) |
Jun
(11) |
Jul
(33) |
Aug
(3) |
Sep
(2) |
Oct
(11) |
Nov
(23) |
Dec
(5) |
2008 |
Jan
(10) |
Feb
(9) |
Mar
|
Apr
(6) |
May
(8) |
Jun
(7) |
Jul
|
Aug
(3) |
Sep
(2) |
Oct
(1) |
Nov
|
Dec
(20) |
2009 |
Jan
(8) |
Feb
(8) |
Mar
(3) |
Apr
(8) |
May
(2) |
Jun
(11) |
Jul
(2) |
Aug
|
Sep
(3) |
Oct
(1) |
Nov
(7) |
Dec
(4) |
2010 |
Jan
(2) |
Feb
(1) |
Mar
(3) |
Apr
|
May
(2) |
Jun
(2) |
Jul
(7) |
Aug
(3) |
Sep
(7) |
Oct
(2) |
Nov
(1) |
Dec
(4) |
2011 |
Jan
(4) |
Feb
(5) |
Mar
|
Apr
(3) |
May
(2) |
Jun
|
Jul
(6) |
Aug
|
Sep
|
Oct
(6) |
Nov
|
Dec
|
2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(3) |
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(5) |
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(7) |
Sep
(2) |
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
(30) |
Apr
(10) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(12) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(1) |
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2024 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
From: <ple...@gm...> - 2024-12-06 11:29:54
|
Hi, there are reports that regexp matching with an end-of-string anchor do not work, they leave a residue in the 'after" match buffer, corrupting subsequent expect calls. Please find examples of these reports below. What is the most efficient way to bring this issue and the various proposed patches to the maintainer's attention? Kind regards, Karl. ### github issue report, including patched version ### https://github.com/jacoby/expect.pm/issues/10 "my $string = "test\r\ntest-end-test\r\nend"; my $pattern = qr/^end$/m; (...) String: test test-end-test end Output: Before: test test- After: -test end Expected output: Before: test test-end-test After:" ### cpan bug report ### https://rt.cpan.org/Public/Bug/Display.html?id=140125 "The following regex will not match correctly (...) According to bisect, this is the first bad commit: 7ee4816fd4a560ff0b9ee14c3f273222b215a8d3 Which did mess with before/match/after. I've copied Gabor Szabo who authored that commit. It was in 2014 and he may or may not be able to help you now..." ### ... and my own initial question on stackoverflow ### https://stackoverflow.com/questions/79247491/expect-module-end-of-string-is-correctly-matched-but-characters-remain-in-aft " spawn id(3): Does `\r\n\r\n{master:0}\r\nroot@router> \r\n\r\n{master:0}\r\nroot@router' match: pattern #1: -re `(?^:[\\r\\n]+[^\\r\\n<]+[#>%] ?$)'? No. spawn id(3): Does `\r\n\r\n{master:0}\r\nroot@router> \r\n\r\n{master:0}\r\nroot@router> ' match: pattern #1: -re `(?^:[\\r\\n]+[^\\r\\n<]+[#>%] ?$)'? YES!! Before match string: `\r\n\r\n{master:0}' Match string: `\r\nroot@router> ' After match string: `\r\n\r\n{master:0}\r\nroot@router> ' Matchlist: () " |
From: Andrea M. <and...@au...> - 2022-11-14 08:17:19
|
When I use this script: #!/usr/bin/perl -w use strict; use IPC::Open2; use IO::Pty; my $pid; my $out; my $in; $in = new IO::Pty; $out = $in->slave; $pid = open2 ($out, $in, './a.out'); while (<$out>) { print $_; } with this C program (compiled to a.out): #include <stdio.h> #include <unistd.h> int main () { printf ("isatty 0 = %d, 1 = %d, 2 = %d\n", isatty (0), isatty (1), isatty (2)); } I get: isatty 0 = 0, 1 = 0, 2 = 1 That means that the pseudo-terminal doesn't convince the isatty function from glibc that it is a terminal (except for stderr that open2 does not redirect). That has unpleasant consequences, such as my C programs using block buffering instead of line buffering when piped to that Perl script - avoiding that is the only reason I tried IO::Pty. Am I doing something wrong? Andrea Monaco |
From: Serge T. <ser...@gm...> - 2018-06-20 09:52:35
|
Thank you Dave, other modules Net::OpenSSH (Net::OpenSSH2, Net::Appliance::Session) are very interesting, but not in my case. The problem is resolving by adding "interactive" at the end of the string: "$login\@$host", "interactive") to switch ssh in interactive mode. 2018-06-10 4:55 GMT+03:00 Dave Jacoby <jac...@gm...>: > I'm happy to look at it further later, but seems like Net::OpenSSH (is that > the module? Going from memory.) is a better choice for this task. > > sent from my pocket supercomputer > > On Sat, Jun 9, 2018, 10:45 AM Serge Torop <ser...@gm...> wrote: >> >> Hello all, >> >> I need to manage switches and I'm using the Expect module (usually >> NET::SSH::Expect). >> >> *Many* models of switches work properly, except one. >> >> To demonstrate it I'm using simple script: >> >> #!/usr/bin/perl >> >> use strict; >> use warnings; >> use Expect; >> use IO::Stty; >> >> my $login = "user"; >> my $host = "10.10.10.1"; >> my $prompt = ">"; >> my $passwd = "pass123"; >> my $timeout = 2; >> >> my @command = ("/usr/bin/ssh", >> "-o StrictHostKeyChecking=no", >> "-o PreferredAuthentications=password", >> "-o PubkeyAuthentication=no", >> "$login\@$host"); >> >> my $exp = new Expect(); >> >> $exp = Expect->spawn(@command) or die "Cannot spawn $command[0]: $!\n"; >> >> $exp->expect(2,'-re',"Password: "); >> >> $exp->send("$passwd\r"); >> $exp->expect($timeout,$prompt); >> >> $exp->send("show version\r"); >> $exp->expect($timeout, $prompt); >> >> The result is: >> >> [user@linuxhost]# ./script >> user@10.10.10.1's password: >> Welcome to SwitchHost console >> >> Enter username: user >> Enter terminal type: vt100 >> SwitchHost:1:> ^[[62;13R [user@linuxhost]# ;13R^C >> >> This is a escape sequences. The script does not return any results. >> >> If I rty to add interact the command - >> $exp->interact(); >> >> I have properly result: >> >> [user@linuxhost]# ./script >> tsp@10.10.10.1's password: >> Welcome to SwitchHost console >> >> Enter username: user >> Enter terminal type: vt100 >> SwitchHost:1:> show version >> SwitchNAT 4080 >> Firmware version: 3.1.3.2.3 >> S/N: 1C8776550B51 >> SwitchHost:2:> quit >> Successfully exit from SwitchHost console >> >> Everything looks good. >> >> I'm try to change TERM settings of my linux console and different >> method (/usr/bin/expect, NET::SSH::Expect etc), >> but result the same. Usually scripts freeze after: >> ^[[62;13R >> >> Also, if I try to connect using /usr/bin/ssh from linux console the >> result always *good*, >> I don't see the ESC sequences. >> >> My question is: Is it possible to handle this sequences (this is >> \x1B\x5B\x33...) or filter it? >> Does this switch using only interact mode (in this case how to manage >> it with scripts)? >> >> >> Additional info: I have logged session to file, here is the top: >> >> ESC[3gESC[39mWelcome to SwitchHost console >> ESC[39m >> ESC[39mEnter username: user^M >> ESC[39mEnter terminal type: vt100^M >> ESC[39mESC[39mSwitchHost:ESC[39m1:ESC[39m> >> [ ... ] >> >> Thank you in advance. >> >> >> >> >> >> >> >> -- >> Serge P. Torop >> >> >> ------------------------------------------------------------------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss -- Serge P. Torop |
From: Serge T. <ser...@gm...> - 2018-06-09 14:45:41
|
Hello all, I need to manage switches and I'm using the Expect module (usually NET::SSH::Expect). *Many* models of switches work properly, except one. To demonstrate it I'm using simple script: #!/usr/bin/perl use strict; use warnings; use Expect; use IO::Stty; my $login = "user"; my $host = "10.10.10.1"; my $prompt = ">"; my $passwd = "pass123"; my $timeout = 2; my @command = ("/usr/bin/ssh", "-o StrictHostKeyChecking=no", "-o PreferredAuthentications=password", "-o PubkeyAuthentication=no", "$login\@$host"); my $exp = new Expect(); $exp = Expect->spawn(@command) or die "Cannot spawn $command[0]: $!\n"; $exp->expect(2,'-re',"Password: "); $exp->send("$passwd\r"); $exp->expect($timeout,$prompt); $exp->send("show version\r"); $exp->expect($timeout, $prompt); The result is: [user@linuxhost]# ./script user@10.10.10.1's password: Welcome to SwitchHost console Enter username: user Enter terminal type: vt100 SwitchHost:1:> ^[[62;13R [user@linuxhost]# ;13R^C This is a escape sequences. The script does not return any results. If I rty to add interact the command - $exp->interact(); I have properly result: [user@linuxhost]# ./script tsp@10.10.10.1's password: Welcome to SwitchHost console Enter username: user Enter terminal type: vt100 SwitchHost:1:> show version SwitchNAT 4080 Firmware version: 3.1.3.2.3 S/N: 1C8776550B51 SwitchHost:2:> quit Successfully exit from SwitchHost console Everything looks good. I'm try to change TERM settings of my linux console and different method (/usr/bin/expect, NET::SSH::Expect etc), but result the same. Usually scripts freeze after: ^[[62;13R Also, if I try to connect using /usr/bin/ssh from linux console the result always *good*, I don't see the ESC sequences. My question is: Is it possible to handle this sequences (this is \x1B\x5B\x33...) or filter it? Does this switch using only interact mode (in this case how to manage it with scripts)? Additional info: I have logged session to file, here is the top: ESC[3gESC[39mWelcome to SwitchHost console ESC[39m ESC[39mEnter username: user^M ESC[39mEnter terminal type: vt100^M ESC[39mESC[39mSwitchHost:ESC[39m1:ESC[39m> [ ... ] Thank you in advance. -- Serge P. Torop |
From: Dave J. <jac...@gm...> - 2017-12-05 14:29:45
|
I have this email and the bug report it mentions open. I have not dived into the Expect code recently, either as a maintainer or as a user, so it will take a little bit before I can get to it. But it is received. I will look into it. On Fri, Nov 24, 2017 at 7:52 AM, Tom Brown <70m...@gm...> wrote: > Dear Perl-Expect fellows, > > as the implementation for the interact-method within Expect.pm is far away > from the TCL-Expect implementation > > (see https://rt.cpan.org/Public/Bug/Display.html?id=56997) > > I am trying to use the method set_seq as workaround. But there is a very > hard > nut I am trying to crack for two days now. I am not sure if its caused by > a bug > in the Expect.pm module or my understanding is wrong how to hand over > escape sequences to the set_seq($sequence,\&function,\@parameters) method. > > For reproduction purposes you can find the whole script below. > > -------------------------------- SCRIPT BEGIN > ------------------------------- > #!/usr/bin/perl > > use strict; > use warnings; > use Expect; > use feature qw(say); > > my %OPT = ( > "login" => "tbrown", > "host" => "rtr", > "prompt" => "RTR#", > "passwd" => "myPasswd", > "timeout" => 2, > ); > > my @command = ("/usr/bin/ssh", > "-o StrictHostKeyChecking=no", > "-o PreferredAuthentications=password", > "-o PubkeyAuthentication=no", > "$OPT{login}\@$OPT{host}"); > > my $exp = new Expect(); > $exp = Expect->spawn(@command) or die "Cannot spawn $command[0]: $!\n"; > $exp->expect(2,'-re',"password: "); > $exp->send("$OPT{passwd}\r"); > $exp->expect($OPT{timeout}, $OPT{prompt}); > > $exp->send("term length 0\r"); > $exp->expect($OPT{timeout}, $OPT{prompt}); > > my @parameters = qw(Parameter1 Parameter2 Parameter3); > my @tunnel_iface = 2; > > $exp->log_stdout(0); > $exp->debug(3); > $exp->exp_internal(1); > $exp->slave->stty(qw(raw -echo)); > > > ### Proper handling of the following escape sequences (keys F1 ~ F3) > $exp->set_seq('\\033OP',\&sh_clock); > $exp->set_seq("\\033OQ",\&sh_arp_vlan, \@parameters); > $exp->set_seq("\\033OR",\&sh_vpn, \@tunnel_iface); > > ### Wrong handling of the following escape sequences (function keys F5) > ### As with beginning of F5 the escape sequence pattern starts with > '^[[15~' > ### it looks like something goes wrong with the second '[' and the followed > ### '15~' > $exp->set_seq('\\033\[15~', \&leave); > $exp->set_seq('X', \&leave); > #$exp->set_seq('\x1b\x5b\x31\x35\x7e', \&leave); > #$exp->set_seq('\\033\x5b15~', \&leave); > #$exp->set_seq('\\033\\03315~', \&leave); > #$exp->set_seq('\\033\x5b15~', \&leave); # \x5b = [ = escape character as > hex > > > $exp->log_stdout(1); > $exp->debug(0); > $exp->exp_internal(0); > > sub sh_clock { > $exp->send("sh clock\r"); > $exp->expect($OPT{timeout}, $OPT{prompt}); > } > > sub sh_arp_vlan { > foreach my $parameter (@_) { > say $parameter; > } > $exp->send("show ip arp vlan 1\r"); > $exp->expect($OPT{timeout}, $OPT{prompt}); > } > > sub sh_vpn { > my $iface = shift; > $exp->send("show crypto isakmp sa\r"); > $exp->expect($OPT{timeout}, $OPT{prompt}); > $exp->send("show crypto ipsec sa interface tunnel $iface\r"); > $exp->expect($OPT{timeout}, $OPT{prompt}); > } > > sub leave { > $exp->send("exit\r"); > $exp->expect($OPT{timeout}, eof); > } > > $exp->interact(); > > > print "##### MATCHED:"; > p $exp->exp_match(); > > --------------------------------- SCRIPT END > -------------------------------- > > The output of debug on invocation and after login is the following: > > RTR#term length 0 > RTR#Escape seq. '\033OP' function for spawn id(6) set to > 'CODE(0x7f88318a72b8)()' > Escape seq. '\033OQ' function for spawn id(6) set to > 'CODE(0x7f88318a7240)()' > Escape seq. '\033OR' function for spawn id(6) set to > 'CODE(0x7f88318a70f0)()' > Escape seq. '\033\[15~' function for spawn id(6) set to > 'CODE(0x7f88318a6f70)()' > Escape seq. 'X' function for spawn id(6) set to 'CODE(0x7f88318a6f70)()' > > My investigations so far: > > ------------------------------------- 1 ------------------------------ > ------- > > $exp->set_seq('\\033\[15~', \&leave); > By pressing F5 the string '5~exit' occurs on the routers shell. Obviously, > the escape sequence seems to be divided and the string "~5" is passed > within @_ to the function &leave). > > ------------------------------------- 2 ------------------------------ > ------- > > $exp->set_seq('X', \&leave); > By pressing just X I get the following: > > Value of @_ is:[] > exit ### End of @_ > Translating "Xexit"...domain server... # < mind the "Xexit"!!! > > Translating "### Value of @_ is:[] > (8.8.8.8) (217.237.150.51) (217.237.148.22) @_ > (8.8.8.8) (217.237.150.51) (217.237.148.22) > % Unknown command or computer name,or unable to find computer address > RTR#exit > Connection to 192.168.3.1 closed. > > Conclusion: Instead calling the function &leave expect sends 'Xexit' to > the > router. Why??? > > But: In case just pressing "ESC" followed by X, the function leave() is > properly called and logged out. > > Conclusion: Pressing ESC before X followed by a proper function call is > the > proof that the method set_seq works as it should - so far at least. > > ------------------------------------- 3 ------------------------------ > ------- > > The following attempts (different variants to catch the escape sequence > properly) doesn't work neither. > > $exp->set_seq('\x1b\x5b\x31\x35\x7e', \&leave); # escape sequence in hex > #$exp->set_seq('\\033\\03315~', \&leave); # > #$exp->set_seq('\\033\[15~', \&leave); > #$exp->set_seq('\\033\x5b15~', \&leave); # \x5b = [ = Escape Character > > ------------------------------------------------------------ > ----------------- > > I am at my wits' end. Any ideas or workarounds how to invoke functions > properly by pressing function keys (using escape sequences)? > > I appreciate any comments. > > Thanks. > > T. > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > -- Dave Jacoby jac...@gm... Don't panic when the crisis is happening, or you won't enjoy it. |
From: Tom B. <70m...@gm...> - 2017-11-24 12:52:19
|
Dear Perl-Expect fellows, as the implementation for the interact-method within Expect.pm is far away from the TCL-Expect implementation (see https://rt.cpan.org/Public/Bug/Display.html?id=56997) I am trying to use the method set_seq as workaround. But there is a very hard nut I am trying to crack for two days now. I am not sure if its caused by a bug in the Expect.pm module or my understanding is wrong how to hand over escape sequences to the set_seq($sequence,\&function,\@parameters) method. For reproduction purposes you can find the whole script below. -------------------------------- SCRIPT BEGIN ------------------------------- #!/usr/bin/perl use strict; use warnings; use Expect; use feature qw(say); my %OPT = ( "login" => "tbrown", "host" => "rtr", "prompt" => "RTR#", "passwd" => "myPasswd", "timeout" => 2, ); my @command = ("/usr/bin/ssh", "-o StrictHostKeyChecking=no", "-o PreferredAuthentications=password", "-o PubkeyAuthentication=no", "$OPT{login}\@$OPT{host}"); my $exp = new Expect(); $exp = Expect->spawn(@command) or die "Cannot spawn $command[0]: $!\n"; $exp->expect(2,'-re',"password: "); $exp->send("$OPT{passwd}\r"); $exp->expect($OPT{timeout}, $OPT{prompt}); $exp->send("term length 0\r"); $exp->expect($OPT{timeout}, $OPT{prompt}); my @parameters = qw(Parameter1 Parameter2 Parameter3); my @tunnel_iface = 2; $exp->log_stdout(0); $exp->debug(3); $exp->exp_internal(1); $exp->slave->stty(qw(raw -echo)); ### Proper handling of the following escape sequences (keys F1 ~ F3) $exp->set_seq('\\033OP',\&sh_clock); $exp->set_seq("\\033OQ",\&sh_arp_vlan, \@parameters); $exp->set_seq("\\033OR",\&sh_vpn, \@tunnel_iface); ### Wrong handling of the following escape sequences (function keys F5) ### As with beginning of F5 the escape sequence pattern starts with '^[[15~' ### it looks like something goes wrong with the second '[' and the followed ### '15~' $exp->set_seq('\\033\[15~', \&leave); $exp->set_seq('X', \&leave); #$exp->set_seq('\x1b\x5b\x31\x35\x7e', \&leave); #$exp->set_seq('\\033\x5b15~', \&leave); #$exp->set_seq('\\033\\03315~', \&leave); #$exp->set_seq('\\033\x5b15~', \&leave); # \x5b = [ = escape character as hex $exp->log_stdout(1); $exp->debug(0); $exp->exp_internal(0); sub sh_clock { $exp->send("sh clock\r"); $exp->expect($OPT{timeout}, $OPT{prompt}); } sub sh_arp_vlan { foreach my $parameter (@_) { say $parameter; } $exp->send("show ip arp vlan 1\r"); $exp->expect($OPT{timeout}, $OPT{prompt}); } sub sh_vpn { my $iface = shift; $exp->send("show crypto isakmp sa\r"); $exp->expect($OPT{timeout}, $OPT{prompt}); $exp->send("show crypto ipsec sa interface tunnel $iface\r"); $exp->expect($OPT{timeout}, $OPT{prompt}); } sub leave { $exp->send("exit\r"); $exp->expect($OPT{timeout}, eof); } $exp->interact(); print "##### MATCHED:"; p $exp->exp_match(); --------------------------------- SCRIPT END -------------------------------- The output of debug on invocation and after login is the following: RTR#term length 0 RTR#Escape seq. '\033OP' function for spawn id(6) set to 'CODE(0x7f88318a72b8)()' Escape seq. '\033OQ' function for spawn id(6) set to 'CODE(0x7f88318a7240)()' Escape seq. '\033OR' function for spawn id(6) set to 'CODE(0x7f88318a70f0)()' Escape seq. '\033\[15~' function for spawn id(6) set to 'CODE(0x7f88318a6f70)()' Escape seq. 'X' function for spawn id(6) set to 'CODE(0x7f88318a6f70)()' My investigations so far: ------------------------------------- 1 ------------------------------------- $exp->set_seq('\\033\[15~', \&leave); By pressing F5 the string '5~exit' occurs on the routers shell. Obviously, the escape sequence seems to be divided and the string "~5" is passed within @_ to the function &leave). ------------------------------------- 2 ------------------------------------- $exp->set_seq('X', \&leave); By pressing just X I get the following: Value of @_ is:[] exit ### End of @_ Translating "Xexit"...domain server... # < mind the "Xexit"!!! Translating "### Value of @_ is:[] (8.8.8.8) (217.237.150.51) (217.237.148.22) @_ (8.8.8.8) (217.237.150.51) (217.237.148.22) % Unknown command or computer name,or unable to find computer address RTR#exit Connection to 192.168.3.1 closed. Conclusion: Instead calling the function &leave expect sends 'Xexit' to the router. Why??? But: In case just pressing "ESC" followed by X, the function leave() is properly called and logged out. Conclusion: Pressing ESC before X followed by a proper function call is the proof that the method set_seq works as it should - so far at least. ------------------------------------- 3 ------------------------------------- The following attempts (different variants to catch the escape sequence properly) doesn't work neither. $exp->set_seq('\x1b\x5b\x31\x35\x7e', \&leave); # escape sequence in hex #$exp->set_seq('\\033\\03315~', \&leave); # #$exp->set_seq('\\033\[15~', \&leave); #$exp->set_seq('\\033\x5b15~', \&leave); # \x5b = [ = Escape Character ----------------------------------------------------------------------------- I am at my wits' end. Any ideas or workarounds how to invoke functions properly by pressing function keys (using escape sequences)? I appreciate any comments. Thanks. T. |
From: Eng. B. <ba...@ya...> - 2017-06-29 12:27:47
|
Hi guys,I have developed a real-time monitoring tool to detect BGP anomalies.Now, I am looking to add gui that shows to users if an anomaly occurs with plotting capability to the data.Is there a such dashboard module that I can use? I tried to use GD::Dashboard but without successful, seems it is not supported anymore. Regards Bahaa |
From: mike n. <xmi...@gm...> - 2017-03-30 13:52:06
|
Great, glad the issue is resolved now. All the best to you Bob! :-) On Mar 30, 2017 1:44 AM, "Bob McGowan" <ram...@gm...> wrote: > Hi Mike, > > Your suggestion did help, but not in the way I thought. > > I did get the prompt I was looking for, but in the process of working > through the code again, I also noticed a PEBKAC error, which when fixed, > the problem went away. > > I had missed getting the right number of arguments to an in-house > module's method, and it was doing exactly what I told it to do. Just > not what I *wanted* it to do. :( > > Thanks for taking the time help. It is appreciated. > > Bob > > > On 03/26/2017 06:29 PM, Bob McGowan wrote: > > Not yet. Hopefully first thing in the morning. > > > > On 03/25/2017 08:03 PM, mike nicholas wrote: > >> Hey Bob, no worries, yup, we got this one. > >> > >> Curious to know if any of those suggestions helped? Were you able to do > >> some tests yet? > >> > >> On Mar 25, 2017 9:43 PM, "Bob McGowan" <ram...@gm...> wrote: > >> > >>> No, I did not. > >>> > >>> I guess I misunderstood the email from the moderator regarding my > >>> attempt to post while not a member of the list. > >>> > >>> I thought the first attempt would be rejected, so I joined the list and > >>> sent the email as a member. > >>> > >>> I assume the first one actually was released, hence the double post. > My > >>> apologies for that. > >>> > >>> By the way, I did answer your first two responses, and thought I had > >>> included the list, but that did not show up in my mailbox (I think I > >>> have things set so it should have). > >>> > >>> Please let me know if you get this, either way. > >>> > >>> Thanks, > >>> > >>> Bob > >>> > >>> On 03/25/2017 12:49 PM, mike nicholas wrote: > >>>> Hello again, Bob, > >>>> > >>>> Did you truly intend to re-send the same email from yesterday? Were > you > >>>> able to test those previous suggestions? > >>>> > >>>> Thanks kindly! > >>>> > >>>> On Mar 25, 2017 8:50 AM, "McGowan Jr, Bob" <bob...@sa...> > wrote: > >>>> > >>>>> Hello List, > >>>>> > >>>>> I'm supporting legacy code that uses Expect, but I'm no expert at > this > >>>>> tool. Nor can I figure out a way to pose the question to the archive > >>>>> server to search for anything helpful, so here I am, hoping for an > >>> answer. > >>>>> Also, I have not signed up to the list, since I hopefully will have > no > >>>>> future needs in this arena. So please reply all. > >>>>> > >>>>> Before the section that does the Expect processing, below, there is a > >>> sub > >>>>> defined as follows: > >>>>> > >>>>> $passHandler = sub { > >>>>> my ($ssh, $logging, $password) = @_; > >>>>> $ssh->log_file(undef); > >>>>> $ssh->stty(qw(-echo)); > >>>>> print $ssh "$password\r"; > >>>>> $ssh->stty(qw(echo)); > >>>>> $pat = quotemeta($password); > >>>>> > >>>>> $ssh->expect(0, '-re', "$pat"); > >>>>> > >>>>> $ssh->log_file(\&logMethod) if $logging; > >>>>> return $ssh->error(); > >>>>> }; > >>>>> > >>>>> There are a number of other patterns to look for besides the two > prompts > >>>>> listed below, each with appropriate logic contained in other 'sub' > >>>>> definitions. My problem is with the second prompt. Also, I'm not > being > >>>>> pedantic here about format or syntax, this is not intended to run > >>>>> (currently). > >>>>> > >>>>> $expectObj->expect($timeout, > >>>>> '-re', $prompt1, sub { > >>>>> $failed = $passHandler($ssh, > $logging, > >>>>> $password); > >>>>> if ($failed) { > >>>>> return "something"; > >>>>> } else { > >>>>> return > exp_continue_timeout(); > >>>>> } > >>>>> }, > >>>>> '-re', $prompt2, sub { > >>>>> $output = $ssh->exp_before(); > >>>>> if ($secondPass) { > >>>>> $failed = $passHandler($ssh, > >>>>> $logging, $password); > >>>>> if ($failed) { > >>>>> return 'something'; > >>>>> } else { > >>>>> return > >>>>> exp_continue_timeout(); > >>>>> } > >>>>> } else { > >>>>> return # an error > >>>>> } > >>>>> }, > >>>>> ... > >>>>> ); > >>>>> > >>>>> I have run the original code with debugging on. > >>>>> > >>>>> Processing $prompt1 happens before processing for $prompt2. > $prompt1 is > >>>>> the login prompt passed through by 'ssh'. > >>>>> > >>>>> Handling the ssh login step is works fine. > >>>>> > >>>>> Processing the second prompt looks for a string like 'Enter secondary > >>>>> password: ' which is detected correctly and processing goes into the > >>>>> passHandler, where the password is sent. > >>>>> > >>>>> The function then does the 'expect' on the password "pattern", which > is > >>>>> there to be sure we don't get any echo'ed password passed through. > >>>>> > >>>>> But in the failing case, there is no password echoed, and the next > set > >>> of > >>>>> returned strings contains stuff that doesn't match, within the > >>>>> passHandler. So it times out. > >>>>> > >>>>> Upon returning to the enclosing 'expect' call, expect immediately > begins > >>>>> 'waiting' for new data. The strings that were picked up in > passHandler > >>> are > >>>>> not looked at, and unfortunately they have the next string being > >>> 'waited' > >>>>> for, so the whole thing times out and processing fails. > >>>>> > >>>>> I'm happy to try to make something that actually runs, if that is > >>> needed, > >>>>> but that will take a bit more time and I hope this is enough to point > >>>>> someone in the right direction. > >>>>> > >>>>> Many thanks, > >>>>> > >>>>> Bob > >>>>> > >>>>> ------------------------------------------------------------ > >>>>> ------------------ > >>>>> Check out the vibrant tech community on one of the world's most > >>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot > >>>>> _______________________________________________ > >>>>> Expectperl-discuss mailing list > >>>>> Exp...@li... > >>>>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > >>>>> > >>>> > >>>> > >>>> ------------------------------------------------------------ > >>> ------------------ > >>>> Check out the vibrant tech community on one of the world's most > >>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot > >>>> > >>>> > >>>> > >>>> _______________________________________________ > >>>> Expectperl-discuss mailing list > >>>> Exp...@li... > >>>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > >>>> > >>> ------------------------------------------------------------ > >>> ------------------ > >>> Check out the vibrant tech community on one of the world's most > >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot > >>> _______________________________________________ > >>> Expectperl-discuss mailing list > >>> Exp...@li... > >>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > >>> > > ------------------------------------------------------------ > ------------------ > > Check out the vibrant tech community on one of the world's most > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > _______________________________________________ > > Expectperl-discuss mailing list > > Exp...@li... > > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: Bob M. <ram...@gm...> - 2017-03-30 06:44:04
|
Hi Mike, Your suggestion did help, but not in the way I thought. I did get the prompt I was looking for, but in the process of working through the code again, I also noticed a PEBKAC error, which when fixed, the problem went away. I had missed getting the right number of arguments to an in-house module's method, and it was doing exactly what I told it to do. Just not what I *wanted* it to do. :( Thanks for taking the time help. It is appreciated. Bob On 03/26/2017 06:29 PM, Bob McGowan wrote: > Not yet. Hopefully first thing in the morning. > > On 03/25/2017 08:03 PM, mike nicholas wrote: >> Hey Bob, no worries, yup, we got this one. >> >> Curious to know if any of those suggestions helped? Were you able to do >> some tests yet? >> >> On Mar 25, 2017 9:43 PM, "Bob McGowan" <ram...@gm...> wrote: >> >>> No, I did not. >>> >>> I guess I misunderstood the email from the moderator regarding my >>> attempt to post while not a member of the list. >>> >>> I thought the first attempt would be rejected, so I joined the list and >>> sent the email as a member. >>> >>> I assume the first one actually was released, hence the double post. My >>> apologies for that. >>> >>> By the way, I did answer your first two responses, and thought I had >>> included the list, but that did not show up in my mailbox (I think I >>> have things set so it should have). >>> >>> Please let me know if you get this, either way. >>> >>> Thanks, >>> >>> Bob >>> >>> On 03/25/2017 12:49 PM, mike nicholas wrote: >>>> Hello again, Bob, >>>> >>>> Did you truly intend to re-send the same email from yesterday? Were you >>>> able to test those previous suggestions? >>>> >>>> Thanks kindly! >>>> >>>> On Mar 25, 2017 8:50 AM, "McGowan Jr, Bob" <bob...@sa...> wrote: >>>> >>>>> Hello List, >>>>> >>>>> I'm supporting legacy code that uses Expect, but I'm no expert at this >>>>> tool. Nor can I figure out a way to pose the question to the archive >>>>> server to search for anything helpful, so here I am, hoping for an >>> answer. >>>>> Also, I have not signed up to the list, since I hopefully will have no >>>>> future needs in this arena. So please reply all. >>>>> >>>>> Before the section that does the Expect processing, below, there is a >>> sub >>>>> defined as follows: >>>>> >>>>> $passHandler = sub { >>>>> my ($ssh, $logging, $password) = @_; >>>>> $ssh->log_file(undef); >>>>> $ssh->stty(qw(-echo)); >>>>> print $ssh "$password\r"; >>>>> $ssh->stty(qw(echo)); >>>>> $pat = quotemeta($password); >>>>> >>>>> $ssh->expect(0, '-re', "$pat"); >>>>> >>>>> $ssh->log_file(\&logMethod) if $logging; >>>>> return $ssh->error(); >>>>> }; >>>>> >>>>> There are a number of other patterns to look for besides the two prompts >>>>> listed below, each with appropriate logic contained in other 'sub' >>>>> definitions. My problem is with the second prompt. Also, I'm not being >>>>> pedantic here about format or syntax, this is not intended to run >>>>> (currently). >>>>> >>>>> $expectObj->expect($timeout, >>>>> '-re', $prompt1, sub { >>>>> $failed = $passHandler($ssh, $logging, >>>>> $password); >>>>> if ($failed) { >>>>> return "something"; >>>>> } else { >>>>> return exp_continue_timeout(); >>>>> } >>>>> }, >>>>> '-re', $prompt2, sub { >>>>> $output = $ssh->exp_before(); >>>>> if ($secondPass) { >>>>> $failed = $passHandler($ssh, >>>>> $logging, $password); >>>>> if ($failed) { >>>>> return 'something'; >>>>> } else { >>>>> return >>>>> exp_continue_timeout(); >>>>> } >>>>> } else { >>>>> return # an error >>>>> } >>>>> }, >>>>> ... >>>>> ); >>>>> >>>>> I have run the original code with debugging on. >>>>> >>>>> Processing $prompt1 happens before processing for $prompt2. $prompt1 is >>>>> the login prompt passed through by 'ssh'. >>>>> >>>>> Handling the ssh login step is works fine. >>>>> >>>>> Processing the second prompt looks for a string like 'Enter secondary >>>>> password: ' which is detected correctly and processing goes into the >>>>> passHandler, where the password is sent. >>>>> >>>>> The function then does the 'expect' on the password "pattern", which is >>>>> there to be sure we don't get any echo'ed password passed through. >>>>> >>>>> But in the failing case, there is no password echoed, and the next set >>> of >>>>> returned strings contains stuff that doesn't match, within the >>>>> passHandler. So it times out. >>>>> >>>>> Upon returning to the enclosing 'expect' call, expect immediately begins >>>>> 'waiting' for new data. The strings that were picked up in passHandler >>> are >>>>> not looked at, and unfortunately they have the next string being >>> 'waited' >>>>> for, so the whole thing times out and processing fails. >>>>> >>>>> I'm happy to try to make something that actually runs, if that is >>> needed, >>>>> but that will take a bit more time and I hope this is enough to point >>>>> someone in the right direction. >>>>> >>>>> Many thanks, >>>>> >>>>> Bob >>>>> >>>>> ------------------------------------------------------------ >>>>> ------------------ >>>>> Check out the vibrant tech community on one of the world's most >>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>> _______________________________________________ >>>>> Expectperl-discuss mailing list >>>>> Exp...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >>>>> >>>> >>>> >>>> ------------------------------------------------------------ >>> ------------------ >>>> Check out the vibrant tech community on one of the world's most >>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>> >>>> >>>> >>>> _______________________________________________ >>>> Expectperl-discuss mailing list >>>> Exp...@li... >>>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >>>> >>> ------------------------------------------------------------ >>> ------------------ >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>> _______________________________________________ >>> Expectperl-discuss mailing list >>> Exp...@li... >>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >>> > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |
From: Roland G. <ro...@gi...> - 2017-03-27 15:02:32
|
Right, I released the posting on hold without noticing that it had been resent. 😊 Sorry for the confusion... Roland -----Original Message----- From: Bob McGowan [mailto:ram...@gm...] Sent: Sonntag, 26. März 2017 04:24 To: mike nicholas <mik...@gm...> Cc: exp...@li... Subject: Re: [Expectperl-discuss] Help with legacy expect code No, I did not. I guess I misunderstood the email from the moderator regarding my attempt to post while not a member of the list. I thought the first attempt would be rejected, so I joined the list and sent the email as a member. I assume the first one actually was released, hence the double post. My apologies for that. By the way, I did answer your first two responses, and thought I had included the list, but that did not show up in my mailbox (I think I have things set so it should have). Please let me know if you get this, either way. Thanks, Bob On 03/25/2017 12:49 PM, mike nicholas wrote: > Hello again, Bob, > > Did you truly intend to re-send the same email from yesterday? Were > you able to test those previous suggestions? > > Thanks kindly! > > On Mar 25, 2017 8:50 AM, "McGowan Jr, Bob" <bob...@sa...> wrote: > >> Hello List, >> >> I'm supporting legacy code that uses Expect, but I'm no expert at >> this tool. Nor can I figure out a way to pose the question to the >> archive server to search for anything helpful, so here I am, hoping for an answer. >> >> Also, I have not signed up to the list, since I hopefully will have >> no future needs in this arena. So please reply all. >> >> Before the section that does the Expect processing, below, there is a >> sub defined as follows: >> >> $passHandler = sub { >> my ($ssh, $logging, $password) = @_; >> $ssh->log_file(undef); >> $ssh->stty(qw(-echo)); >> print $ssh "$password\r"; >> $ssh->stty(qw(echo)); >> $pat = quotemeta($password); >> >> $ssh->expect(0, '-re', "$pat"); >> >> $ssh->log_file(\&logMethod) if $logging; >> return $ssh->error(); >> }; >> >> There are a number of other patterns to look for besides the two >> prompts listed below, each with appropriate logic contained in other 'sub' >> definitions. My problem is with the second prompt. Also, I'm not >> being pedantic here about format or syntax, this is not intended to >> run (currently). >> >> $expectObj->expect($timeout, >> '-re', $prompt1, sub { >> $failed = $passHandler($ssh, >> $logging, $password); >> if ($failed) { >> return "something"; >> } else { >> return exp_continue_timeout(); >> } >> }, >> '-re', $prompt2, sub { >> $output = $ssh->exp_before(); >> if ($secondPass) { >> $failed = $passHandler($ssh, >> $logging, $password); >> if ($failed) { >> return 'something'; >> } else { >> return >> exp_continue_timeout(); >> } >> } else { >> return # an error >> } >> }, >> ... >> ); >> >> I have run the original code with debugging on. >> >> Processing $prompt1 happens before processing for $prompt2. $prompt1 >> is the login prompt passed through by 'ssh'. >> >> Handling the ssh login step is works fine. >> >> Processing the second prompt looks for a string like 'Enter secondary >> password: ' which is detected correctly and processing goes into the >> passHandler, where the password is sent. >> >> The function then does the 'expect' on the password "pattern", which >> is there to be sure we don't get any echo'ed password passed through. >> >> But in the failing case, there is no password echoed, and the next >> set of returned strings contains stuff that doesn't match, within the >> passHandler. So it times out. >> >> Upon returning to the enclosing 'expect' call, expect immediately >> begins 'waiting' for new data. The strings that were picked up in >> passHandler are not looked at, and unfortunately they have the next string being 'waited' >> for, so the whole thing times out and processing fails. >> >> I'm happy to try to make something that actually runs, if that is >> needed, but that will take a bit more time and I hope this is enough >> to point someone in the right direction. >> >> Many thanks, >> >> Bob >> >> ------------------------------------------------------------ >> ------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> > > > > ---------------------------------------------------------------------- > -------- Check out the vibrant tech community on one of the world's > most engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > > > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |
From: Bob M. <ram...@gm...> - 2017-03-27 01:30:12
|
Not yet. Hopefully first thing in the morning. On 03/25/2017 08:03 PM, mike nicholas wrote: > Hey Bob, no worries, yup, we got this one. > > Curious to know if any of those suggestions helped? Were you able to do > some tests yet? > > On Mar 25, 2017 9:43 PM, "Bob McGowan" <ram...@gm...> wrote: > >> No, I did not. >> >> I guess I misunderstood the email from the moderator regarding my >> attempt to post while not a member of the list. >> >> I thought the first attempt would be rejected, so I joined the list and >> sent the email as a member. >> >> I assume the first one actually was released, hence the double post. My >> apologies for that. >> >> By the way, I did answer your first two responses, and thought I had >> included the list, but that did not show up in my mailbox (I think I >> have things set so it should have). >> >> Please let me know if you get this, either way. >> >> Thanks, >> >> Bob >> >> On 03/25/2017 12:49 PM, mike nicholas wrote: >>> Hello again, Bob, >>> >>> Did you truly intend to re-send the same email from yesterday? Were you >>> able to test those previous suggestions? >>> >>> Thanks kindly! >>> >>> On Mar 25, 2017 8:50 AM, "McGowan Jr, Bob" <bob...@sa...> wrote: >>> >>>> Hello List, >>>> >>>> I'm supporting legacy code that uses Expect, but I'm no expert at this >>>> tool. Nor can I figure out a way to pose the question to the archive >>>> server to search for anything helpful, so here I am, hoping for an >> answer. >>>> >>>> Also, I have not signed up to the list, since I hopefully will have no >>>> future needs in this arena. So please reply all. >>>> >>>> Before the section that does the Expect processing, below, there is a >> sub >>>> defined as follows: >>>> >>>> $passHandler = sub { >>>> my ($ssh, $logging, $password) = @_; >>>> $ssh->log_file(undef); >>>> $ssh->stty(qw(-echo)); >>>> print $ssh "$password\r"; >>>> $ssh->stty(qw(echo)); >>>> $pat = quotemeta($password); >>>> >>>> $ssh->expect(0, '-re', "$pat"); >>>> >>>> $ssh->log_file(\&logMethod) if $logging; >>>> return $ssh->error(); >>>> }; >>>> >>>> There are a number of other patterns to look for besides the two prompts >>>> listed below, each with appropriate logic contained in other 'sub' >>>> definitions. My problem is with the second prompt. Also, I'm not being >>>> pedantic here about format or syntax, this is not intended to run >>>> (currently). >>>> >>>> $expectObj->expect($timeout, >>>> '-re', $prompt1, sub { >>>> $failed = $passHandler($ssh, $logging, >>>> $password); >>>> if ($failed) { >>>> return "something"; >>>> } else { >>>> return exp_continue_timeout(); >>>> } >>>> }, >>>> '-re', $prompt2, sub { >>>> $output = $ssh->exp_before(); >>>> if ($secondPass) { >>>> $failed = $passHandler($ssh, >>>> $logging, $password); >>>> if ($failed) { >>>> return 'something'; >>>> } else { >>>> return >>>> exp_continue_timeout(); >>>> } >>>> } else { >>>> return # an error >>>> } >>>> }, >>>> ... >>>> ); >>>> >>>> I have run the original code with debugging on. >>>> >>>> Processing $prompt1 happens before processing for $prompt2. $prompt1 is >>>> the login prompt passed through by 'ssh'. >>>> >>>> Handling the ssh login step is works fine. >>>> >>>> Processing the second prompt looks for a string like 'Enter secondary >>>> password: ' which is detected correctly and processing goes into the >>>> passHandler, where the password is sent. >>>> >>>> The function then does the 'expect' on the password "pattern", which is >>>> there to be sure we don't get any echo'ed password passed through. >>>> >>>> But in the failing case, there is no password echoed, and the next set >> of >>>> returned strings contains stuff that doesn't match, within the >>>> passHandler. So it times out. >>>> >>>> Upon returning to the enclosing 'expect' call, expect immediately begins >>>> 'waiting' for new data. The strings that were picked up in passHandler >> are >>>> not looked at, and unfortunately they have the next string being >> 'waited' >>>> for, so the whole thing times out and processing fails. >>>> >>>> I'm happy to try to make something that actually runs, if that is >> needed, >>>> but that will take a bit more time and I hope this is enough to point >>>> someone in the right direction. >>>> >>>> Many thanks, >>>> >>>> Bob >>>> >>>> ------------------------------------------------------------ >>>> ------------------ >>>> Check out the vibrant tech community on one of the world's most >>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>> _______________________________________________ >>>> Expectperl-discuss mailing list >>>> Exp...@li... >>>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >>>> >>> >>> >>> >>> ------------------------------------------------------------ >> ------------------ >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>> >>> >>> >>> _______________________________________________ >>> Expectperl-discuss mailing list >>> Exp...@li... >>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >>> >> >> ------------------------------------------------------------ >> ------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> > |
From: mike n. <xmi...@gm...> - 2017-03-26 03:03:41
|
Hey Bob, no worries, yup, we got this one. Curious to know if any of those suggestions helped? Were you able to do some tests yet? On Mar 25, 2017 9:43 PM, "Bob McGowan" <ram...@gm...> wrote: > No, I did not. > > I guess I misunderstood the email from the moderator regarding my > attempt to post while not a member of the list. > > I thought the first attempt would be rejected, so I joined the list and > sent the email as a member. > > I assume the first one actually was released, hence the double post. My > apologies for that. > > By the way, I did answer your first two responses, and thought I had > included the list, but that did not show up in my mailbox (I think I > have things set so it should have). > > Please let me know if you get this, either way. > > Thanks, > > Bob > > On 03/25/2017 12:49 PM, mike nicholas wrote: > > Hello again, Bob, > > > > Did you truly intend to re-send the same email from yesterday? Were you > > able to test those previous suggestions? > > > > Thanks kindly! > > > > On Mar 25, 2017 8:50 AM, "McGowan Jr, Bob" <bob...@sa...> wrote: > > > >> Hello List, > >> > >> I'm supporting legacy code that uses Expect, but I'm no expert at this > >> tool. Nor can I figure out a way to pose the question to the archive > >> server to search for anything helpful, so here I am, hoping for an > answer. > >> > >> Also, I have not signed up to the list, since I hopefully will have no > >> future needs in this arena. So please reply all. > >> > >> Before the section that does the Expect processing, below, there is a > sub > >> defined as follows: > >> > >> $passHandler = sub { > >> my ($ssh, $logging, $password) = @_; > >> $ssh->log_file(undef); > >> $ssh->stty(qw(-echo)); > >> print $ssh "$password\r"; > >> $ssh->stty(qw(echo)); > >> $pat = quotemeta($password); > >> > >> $ssh->expect(0, '-re', "$pat"); > >> > >> $ssh->log_file(\&logMethod) if $logging; > >> return $ssh->error(); > >> }; > >> > >> There are a number of other patterns to look for besides the two prompts > >> listed below, each with appropriate logic contained in other 'sub' > >> definitions. My problem is with the second prompt. Also, I'm not being > >> pedantic here about format or syntax, this is not intended to run > >> (currently). > >> > >> $expectObj->expect($timeout, > >> '-re', $prompt1, sub { > >> $failed = $passHandler($ssh, $logging, > >> $password); > >> if ($failed) { > >> return "something"; > >> } else { > >> return exp_continue_timeout(); > >> } > >> }, > >> '-re', $prompt2, sub { > >> $output = $ssh->exp_before(); > >> if ($secondPass) { > >> $failed = $passHandler($ssh, > >> $logging, $password); > >> if ($failed) { > >> return 'something'; > >> } else { > >> return > >> exp_continue_timeout(); > >> } > >> } else { > >> return # an error > >> } > >> }, > >> ... > >> ); > >> > >> I have run the original code with debugging on. > >> > >> Processing $prompt1 happens before processing for $prompt2. $prompt1 is > >> the login prompt passed through by 'ssh'. > >> > >> Handling the ssh login step is works fine. > >> > >> Processing the second prompt looks for a string like 'Enter secondary > >> password: ' which is detected correctly and processing goes into the > >> passHandler, where the password is sent. > >> > >> The function then does the 'expect' on the password "pattern", which is > >> there to be sure we don't get any echo'ed password passed through. > >> > >> But in the failing case, there is no password echoed, and the next set > of > >> returned strings contains stuff that doesn't match, within the > >> passHandler. So it times out. > >> > >> Upon returning to the enclosing 'expect' call, expect immediately begins > >> 'waiting' for new data. The strings that were picked up in passHandler > are > >> not looked at, and unfortunately they have the next string being > 'waited' > >> for, so the whole thing times out and processing fails. > >> > >> I'm happy to try to make something that actually runs, if that is > needed, > >> but that will take a bit more time and I hope this is enough to point > >> someone in the right direction. > >> > >> Many thanks, > >> > >> Bob > >> > >> ------------------------------------------------------------ > >> ------------------ > >> Check out the vibrant tech community on one of the world's most > >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot > >> _______________________________________________ > >> Expectperl-discuss mailing list > >> Exp...@li... > >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > >> > > > > > > > > ------------------------------------------------------------ > ------------------ > > Check out the vibrant tech community on one of the world's most > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > > > > > > > _______________________________________________ > > Expectperl-discuss mailing list > > Exp...@li... > > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: Bob M. <ram...@gm...> - 2017-03-26 02:43:04
|
No, I did not. I guess I misunderstood the email from the moderator regarding my attempt to post while not a member of the list. I thought the first attempt would be rejected, so I joined the list and sent the email as a member. I assume the first one actually was released, hence the double post. My apologies for that. By the way, I did answer your first two responses, and thought I had included the list, but that did not show up in my mailbox (I think I have things set so it should have). Please let me know if you get this, either way. Thanks, Bob On 03/25/2017 12:49 PM, mike nicholas wrote: > Hello again, Bob, > > Did you truly intend to re-send the same email from yesterday? Were you > able to test those previous suggestions? > > Thanks kindly! > > On Mar 25, 2017 8:50 AM, "McGowan Jr, Bob" <bob...@sa...> wrote: > >> Hello List, >> >> I'm supporting legacy code that uses Expect, but I'm no expert at this >> tool. Nor can I figure out a way to pose the question to the archive >> server to search for anything helpful, so here I am, hoping for an answer. >> >> Also, I have not signed up to the list, since I hopefully will have no >> future needs in this arena. So please reply all. >> >> Before the section that does the Expect processing, below, there is a sub >> defined as follows: >> >> $passHandler = sub { >> my ($ssh, $logging, $password) = @_; >> $ssh->log_file(undef); >> $ssh->stty(qw(-echo)); >> print $ssh "$password\r"; >> $ssh->stty(qw(echo)); >> $pat = quotemeta($password); >> >> $ssh->expect(0, '-re', "$pat"); >> >> $ssh->log_file(\&logMethod) if $logging; >> return $ssh->error(); >> }; >> >> There are a number of other patterns to look for besides the two prompts >> listed below, each with appropriate logic contained in other 'sub' >> definitions. My problem is with the second prompt. Also, I'm not being >> pedantic here about format or syntax, this is not intended to run >> (currently). >> >> $expectObj->expect($timeout, >> '-re', $prompt1, sub { >> $failed = $passHandler($ssh, $logging, >> $password); >> if ($failed) { >> return "something"; >> } else { >> return exp_continue_timeout(); >> } >> }, >> '-re', $prompt2, sub { >> $output = $ssh->exp_before(); >> if ($secondPass) { >> $failed = $passHandler($ssh, >> $logging, $password); >> if ($failed) { >> return 'something'; >> } else { >> return >> exp_continue_timeout(); >> } >> } else { >> return # an error >> } >> }, >> ... >> ); >> >> I have run the original code with debugging on. >> >> Processing $prompt1 happens before processing for $prompt2. $prompt1 is >> the login prompt passed through by 'ssh'. >> >> Handling the ssh login step is works fine. >> >> Processing the second prompt looks for a string like 'Enter secondary >> password: ' which is detected correctly and processing goes into the >> passHandler, where the password is sent. >> >> The function then does the 'expect' on the password "pattern", which is >> there to be sure we don't get any echo'ed password passed through. >> >> But in the failing case, there is no password echoed, and the next set of >> returned strings contains stuff that doesn't match, within the >> passHandler. So it times out. >> >> Upon returning to the enclosing 'expect' call, expect immediately begins >> 'waiting' for new data. The strings that were picked up in passHandler are >> not looked at, and unfortunately they have the next string being 'waited' >> for, so the whole thing times out and processing fails. >> >> I'm happy to try to make something that actually runs, if that is needed, >> but that will take a bit more time and I hope this is enough to point >> someone in the right direction. >> >> Many thanks, >> >> Bob >> >> ------------------------------------------------------------ >> ------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> > > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > > > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: mike n. <xmi...@gm...> - 2017-03-25 19:49:35
|
Hello again, Bob, Did you truly intend to re-send the same email from yesterday? Were you able to test those previous suggestions? Thanks kindly! On Mar 25, 2017 8:50 AM, "McGowan Jr, Bob" <bob...@sa...> wrote: > Hello List, > > I'm supporting legacy code that uses Expect, but I'm no expert at this > tool. Nor can I figure out a way to pose the question to the archive > server to search for anything helpful, so here I am, hoping for an answer. > > Also, I have not signed up to the list, since I hopefully will have no > future needs in this arena. So please reply all. > > Before the section that does the Expect processing, below, there is a sub > defined as follows: > > $passHandler = sub { > my ($ssh, $logging, $password) = @_; > $ssh->log_file(undef); > $ssh->stty(qw(-echo)); > print $ssh "$password\r"; > $ssh->stty(qw(echo)); > $pat = quotemeta($password); > > $ssh->expect(0, '-re', "$pat"); > > $ssh->log_file(\&logMethod) if $logging; > return $ssh->error(); > }; > > There are a number of other patterns to look for besides the two prompts > listed below, each with appropriate logic contained in other 'sub' > definitions. My problem is with the second prompt. Also, I'm not being > pedantic here about format or syntax, this is not intended to run > (currently). > > $expectObj->expect($timeout, > '-re', $prompt1, sub { > $failed = $passHandler($ssh, $logging, > $password); > if ($failed) { > return "something"; > } else { > return exp_continue_timeout(); > } > }, > '-re', $prompt2, sub { > $output = $ssh->exp_before(); > if ($secondPass) { > $failed = $passHandler($ssh, > $logging, $password); > if ($failed) { > return 'something'; > } else { > return > exp_continue_timeout(); > } > } else { > return # an error > } > }, > ... > ); > > I have run the original code with debugging on. > > Processing $prompt1 happens before processing for $prompt2. $prompt1 is > the login prompt passed through by 'ssh'. > > Handling the ssh login step is works fine. > > Processing the second prompt looks for a string like 'Enter secondary > password: ' which is detected correctly and processing goes into the > passHandler, where the password is sent. > > The function then does the 'expect' on the password "pattern", which is > there to be sure we don't get any echo'ed password passed through. > > But in the failing case, there is no password echoed, and the next set of > returned strings contains stuff that doesn't match, within the > passHandler. So it times out. > > Upon returning to the enclosing 'expect' call, expect immediately begins > 'waiting' for new data. The strings that were picked up in passHandler are > not looked at, and unfortunately they have the next string being 'waited' > for, so the whole thing times out and processing fails. > > I'm happy to try to make something that actually runs, if that is needed, > but that will take a bit more time and I hope this is enough to point > someone in the right direction. > > Many thanks, > > Bob > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: Bob M. <ram...@gm...> - 2017-03-25 03:53:05
|
Hi Mike, No need for such formality, I generally respond well to Bob :) I like your suggestions, particularly the second. In hindsight (which is almost always 20/20, or better), I wonder why I didn't think of it. It is so obvious. :( I will come back once I've tried it, and let you know how it worked out. Thanks, Bob On 03/24/2017 04:09 PM, mike nicholas wrote: > Or perhaps, send a carriage return from the enclosing expect call, > after it returns back, to get another prompt back to match for and > continue execution ? > > On Fri, Mar 24, 2017 at 6:04 PM, mike nicholas > <xmi...@gm... <mailto:xmi...@gm...>> wrote: > > Hi Mr. McGowan, > > Just a shot in the dark, but: > > # instead of this: > ################## > > $ssh->expect(0, '-re', "$pat"); > $ssh->log_file(\&logMethod) if $logging; > return $ssh->error(); > }; > > # You may want to try: > ###################### > > $ssh->expect(5, > [ '-re', $pat => sub { $ssh->log_file(\&logMethod) if > $logging; > return $ssh->error(); > }], > > ['-re', $contains_stuff => sub { break; > }], > ); > > Maybe try setting $contains_stuff to something you would expect on > success i.e. no pw being echo'd back ? > > On Fri, Mar 24, 2017 at 4:52 PM, Bob McGowan <ram...@gm... > <mailto:ram...@gm...>> wrote: > > Hello List, > > I'm supporting legacy code that uses Expect, but I'm no expert > with this tool. Nor can I figure out a way to pose the > question to the archive server to search for anything helpful, > so here I am, hoping for an answer. :) > > Before the section that does the Expect processing, there is a > sub defined as follows: > > $passHandler = sub { > my ($ssh, $logging, $password) = @_; > $ssh->log_file(undef); > $ssh->stty(qw(-echo)); > print $ssh "$password\r"; > $ssh->stty(qw(echo)); > $pat = quotemeta($password); > > $ssh->expect(0, '-re', "$pat"); > > $ssh->log_file(\&logMethod) if $logging; > return $ssh->error(); > }; > > There are a number of other patterns to look for besides the > two prompts listed below, each with appropriate logic > contained in other 'sub' definitions. My problem is with the > second prompt. Also, I'm not being pedantic here about format > or syntax, this is not intended to run (currently). > > $expectObj->expect($timeout, > '-re', $prompt1, sub { > $failed = $passHandler->($ssh, $logging, > $password); > if ($failed) { > return "something"; > } else { > return exp_continue_timeout(); > } > }, > '-re', $prompt2, sub { > $output = $ssh->exp_before(); > if ($secondPass) { > $failed = $passHandler->($ssh, $logging, > $secondPass); > if ($failed) { > return 'something'; > } else { > return exp_continue_timeout(); > } > } else { > return # an error > } > }, > ... > ); > > I have run the original code with debugging on. > > Processing $prompt1 happens before processing for $prompt2. > $prompt1 is the login prompt passed through by 'ssh'. > > Handling the ssh login step works fine. > > Processing the second prompt looks for a string like 'Enter > secondary password: ' which is detected correctly and > processing goes into the passHandler, where the password is sent. > > The function then does the 'expect' on the password "pattern", > which is there to be sure we don't get any echo'ed password > passed through. > > But in the failing case, there is no password echoed, and the > next set of returned strings contains stuff that doesn't > match, within the passHandler. So it times out. > > Upon returning to the enclosing 'expect' call, expect > immediately begins 'waiting' for new data. The strings that > were picked up in passHandler are not looked at, and > unfortunately they have the next string being 'waited' for, so > the whole thing times out and processing fails. > > I'm happy to try to make something that actually runs, if that > is needed, but that will take a bit more time and I hope this > is enough to point someone in the right direction. > > Many thanks, > > Bob > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > <mailto:Exp...@li...> > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > <https://lists.sourceforge.net/lists/listinfo/expectperl-discuss> > > > |
From: mike n. <xmi...@gm...> - 2017-03-24 23:09:51
|
Or perhaps, send a carriage return from the enclosing expect call, after it returns back, to get another prompt back to match for and continue execution ? On Fri, Mar 24, 2017 at 6:04 PM, mike nicholas <xmi...@gm...> wrote: > Hi Mr. McGowan, > > Just a shot in the dark, but: > > # instead of this: > ################## > > $ssh->expect(0, '-re', "$pat"); > $ssh->log_file(\&logMethod) if $logging; > return $ssh->error(); > }; > > # You may want to try: > ###################### > > $ssh->expect(5, > [ '-re', $pat => sub { $ssh->log_file(\&logMethod) if $logging; > return $ssh->error(); > }], > > ['-re', $contains_stuff => sub { break; > }], > ); > > Maybe try setting $contains_stuff to something you would expect on success > i.e. no pw being echo'd back ? > > On Fri, Mar 24, 2017 at 4:52 PM, Bob McGowan <ram...@gm...> wrote: > >> Hello List, >> >> I'm supporting legacy code that uses Expect, but I'm no expert with this >> tool. Nor can I figure out a way to pose the question to the archive >> server to search for anything helpful, so here I am, hoping for an answer. >> :) >> >> Before the section that does the Expect processing, there is a sub >> defined as follows: >> >> $passHandler = sub { >> my ($ssh, $logging, $password) = @_; >> $ssh->log_file(undef); >> $ssh->stty(qw(-echo)); >> print $ssh "$password\r"; >> $ssh->stty(qw(echo)); >> $pat = quotemeta($password); >> >> $ssh->expect(0, '-re', "$pat"); >> >> $ssh->log_file(\&logMethod) if $logging; >> return $ssh->error(); >> }; >> >> There are a number of other patterns to look for besides the two prompts >> listed below, each with appropriate logic contained in other 'sub' >> definitions. My problem is with the second prompt. Also, I'm not being >> pedantic here about format or syntax, this is not intended to run >> (currently). >> >> $expectObj->expect($timeout, >> '-re', $prompt1, sub { >> $failed = $passHandler->($ssh, $logging, $password); >> if ($failed) { >> return "something"; >> } else { >> return exp_continue_timeout(); >> } >> }, >> '-re', $prompt2, sub { >> $output = $ssh->exp_before(); >> if ($secondPass) { >> $failed = $passHandler->($ssh, $logging, $secondPass); >> if ($failed) { >> return 'something'; >> } else { >> return exp_continue_timeout(); >> } >> } else { >> return # an error >> } >> }, >> ... >> ); >> >> I have run the original code with debugging on. >> >> Processing $prompt1 happens before processing for $prompt2. $prompt1 is >> the login prompt passed through by 'ssh'. >> >> Handling the ssh login step works fine. >> >> Processing the second prompt looks for a string like 'Enter secondary >> password: ' which is detected correctly and processing goes into the >> passHandler, where the password is sent. >> >> The function then does the 'expect' on the password "pattern", which is >> there to be sure we don't get any echo'ed password passed through. >> >> But in the failing case, there is no password echoed, and the next set of >> returned strings contains stuff that doesn't match, within the >> passHandler. So it times out. >> >> Upon returning to the enclosing 'expect' call, expect immediately begins >> 'waiting' for new data. The strings that were picked up in passHandler are >> not looked at, and unfortunately they have the next string being 'waited' >> for, so the whole thing times out and processing fails. >> >> I'm happy to try to make something that actually runs, if that is needed, >> but that will take a bit more time and I hope this is enough to point >> someone in the right direction. >> >> Many thanks, >> >> Bob >> >> >> ------------------------------------------------------------ >> ------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> >> > |
From: mike n. <xmi...@gm...> - 2017-03-24 23:04:17
|
Hi Mr. McGowan, Just a shot in the dark, but: # instead of this: ################## $ssh->expect(0, '-re', "$pat"); $ssh->log_file(\&logMethod) if $logging; return $ssh->error(); }; # You may want to try: ###################### $ssh->expect(5, [ '-re', $pat => sub { $ssh->log_file(\&logMethod) if $logging; return $ssh->error(); }], ['-re', $contains_stuff => sub { break; }], ); Maybe try setting $contains_stuff to something you would expect on success i.e. no pw being echo'd back ? On Fri, Mar 24, 2017 at 4:52 PM, Bob McGowan <ram...@gm...> wrote: > Hello List, > > I'm supporting legacy code that uses Expect, but I'm no expert with this > tool. Nor can I figure out a way to pose the question to the archive > server to search for anything helpful, so here I am, hoping for an answer. > :) > > Before the section that does the Expect processing, there is a sub defined > as follows: > > $passHandler = sub { > my ($ssh, $logging, $password) = @_; > $ssh->log_file(undef); > $ssh->stty(qw(-echo)); > print $ssh "$password\r"; > $ssh->stty(qw(echo)); > $pat = quotemeta($password); > > $ssh->expect(0, '-re', "$pat"); > > $ssh->log_file(\&logMethod) if $logging; > return $ssh->error(); > }; > > There are a number of other patterns to look for besides the two prompts > listed below, each with appropriate logic contained in other 'sub' > definitions. My problem is with the second prompt. Also, I'm not being > pedantic here about format or syntax, this is not intended to run > (currently). > > $expectObj->expect($timeout, > '-re', $prompt1, sub { > $failed = $passHandler->($ssh, $logging, $password); > if ($failed) { > return "something"; > } else { > return exp_continue_timeout(); > } > }, > '-re', $prompt2, sub { > $output = $ssh->exp_before(); > if ($secondPass) { > $failed = $passHandler->($ssh, $logging, $secondPass); > if ($failed) { > return 'something'; > } else { > return exp_continue_timeout(); > } > } else { > return # an error > } > }, > ... > ); > > I have run the original code with debugging on. > > Processing $prompt1 happens before processing for $prompt2. $prompt1 is > the login prompt passed through by 'ssh'. > > Handling the ssh login step works fine. > > Processing the second prompt looks for a string like 'Enter secondary > password: ' which is detected correctly and processing goes into the > passHandler, where the password is sent. > > The function then does the 'expect' on the password "pattern", which is > there to be sure we don't get any echo'ed password passed through. > > But in the failing case, there is no password echoed, and the next set of > returned strings contains stuff that doesn't match, within the > passHandler. So it times out. > > Upon returning to the enclosing 'expect' call, expect immediately begins > 'waiting' for new data. The strings that were picked up in passHandler are > not looked at, and unfortunately they have the next string being 'waited' > for, so the whole thing times out and processing fails. > > I'm happy to try to make something that actually runs, if that is needed, > but that will take a bit more time and I hope this is enough to point > someone in the right direction. > > Many thanks, > > Bob > > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > |
From: Bob M. <ram...@gm...> - 2017-03-24 21:52:15
|
Hello List, I'm supporting legacy code that uses Expect, but I'm no expert with this tool. Nor can I figure out a way to pose the question to the archive server to search for anything helpful, so here I am, hoping for an answer. :) Before the section that does the Expect processing, there is a sub defined as follows: $passHandler = sub { my ($ssh, $logging, $password) = @_; $ssh->log_file(undef); $ssh->stty(qw(-echo)); print $ssh "$password\r"; $ssh->stty(qw(echo)); $pat = quotemeta($password); $ssh->expect(0, '-re', "$pat"); $ssh->log_file(\&logMethod) if $logging; return $ssh->error(); }; There are a number of other patterns to look for besides the two prompts listed below, each with appropriate logic contained in other 'sub' definitions. My problem is with the second prompt. Also, I'm not being pedantic here about format or syntax, this is not intended to run (currently). $expectObj->expect($timeout, '-re', $prompt1, sub { $failed = $passHandler->($ssh, $logging, $password); if ($failed) { return "something"; } else { return exp_continue_timeout(); } }, '-re', $prompt2, sub { $output = $ssh->exp_before(); if ($secondPass) { $failed = $passHandler->($ssh, $logging, $secondPass); if ($failed) { return 'something'; } else { return exp_continue_timeout(); } } else { return # an error } }, ... ); I have run the original code with debugging on. Processing $prompt1 happens before processing for $prompt2. $prompt1 is the login prompt passed through by 'ssh'. Handling the ssh login step works fine. Processing the second prompt looks for a string like 'Enter secondary password: ' which is detected correctly and processing goes into the passHandler, where the password is sent. The function then does the 'expect' on the password "pattern", which is there to be sure we don't get any echo'ed password passed through. But in the failing case, there is no password echoed, and the next set of returned strings contains stuff that doesn't match, within the passHandler. So it times out. Upon returning to the enclosing 'expect' call, expect immediately begins 'waiting' for new data. The strings that were picked up in passHandler are not looked at, and unfortunately they have the next string being 'waited' for, so the whole thing times out and processing fails. I'm happy to try to make something that actually runs, if that is needed, but that will take a bit more time and I hope this is enough to point someone in the right direction. Many thanks, Bob |
From: McGowan J. B. <bob...@sa...> - 2017-03-23 23:30:34
|
Hello List, I'm supporting legacy code that uses Expect, but I'm no expert at this tool. Nor can I figure out a way to pose the question to the archive server to search for anything helpful, so here I am, hoping for an answer. Also, I have not signed up to the list, since I hopefully will have no future needs in this arena. So please reply all. Before the section that does the Expect processing, below, there is a sub defined as follows: $passHandler = sub { my ($ssh, $logging, $password) = @_; $ssh->log_file(undef); $ssh->stty(qw(-echo)); print $ssh "$password\r"; $ssh->stty(qw(echo)); $pat = quotemeta($password); $ssh->expect(0, '-re', "$pat"); $ssh->log_file(\&logMethod) if $logging; return $ssh->error(); }; There are a number of other patterns to look for besides the two prompts listed below, each with appropriate logic contained in other 'sub' definitions. My problem is with the second prompt. Also, I'm not being pedantic here about format or syntax, this is not intended to run (currently). $expectObj->expect($timeout, '-re', $prompt1, sub { $failed = $passHandler($ssh, $logging, $password); if ($failed) { return "something"; } else { return exp_continue_timeout(); } }, '-re', $prompt2, sub { $output = $ssh->exp_before(); if ($secondPass) { $failed = $passHandler($ssh, $logging, $password); if ($failed) { return 'something'; } else { return exp_continue_timeout(); } } else { return # an error } }, ... ); I have run the original code with debugging on. Processing $prompt1 happens before processing for $prompt2. $prompt1 is the login prompt passed through by 'ssh'. Handling the ssh login step is works fine. Processing the second prompt looks for a string like 'Enter secondary password: ' which is detected correctly and processing goes into the passHandler, where the password is sent. The function then does the 'expect' on the password "pattern", which is there to be sure we don't get any echo'ed password passed through. But in the failing case, there is no password echoed, and the next set of returned strings contains stuff that doesn't match, within the passHandler. So it times out. Upon returning to the enclosing 'expect' call, expect immediately begins 'waiting' for new data. The strings that were picked up in passHandler are not looked at, and unfortunately they have the next string being 'waited' for, so the whole thing times out and processing fails. I'm happy to try to make something that actually runs, if that is needed, but that will take a bit more time and I hope this is enough to point someone in the right direction. Many thanks, Bob |
From: David V. <Dav...@kc...> - 2015-05-21 14:36:29
|
Hi, I'm using expect.pm to automate an application that telnets to a remote server using xterm emulation. I can log in to the remote system and navigate down the menu system to get the data I require, but the system requires a PF2 sequence to move back up the menu tree so it can repeat the loop. I've tried the following but it seems to have no effect:- $exp->send ("\033OQ") ; Anyone got any idea what I'm doing wrong? Apologies if this is a bit of a basic question, I'm quite new to all this. Kind Regards Dave This email has been scanned for all viruses. Please consider the environment before printing this email. The content of this email and any attachment is private and may be privileged. If you are not the intended recipient, any use, disclosure, copying or forwarding of this email and/or its attachments is unauthorised. If you have received this email in error please notify the sender by email and delete this message and any attachments immediately. Nothing in this email shall bind the Company or any of its subsidiaries or businesses in any contract or obligation, unless we have specifically agreed to be bound. KCOM Group PLC is a public limited company incorporated in England and Wales, company number 02150618 and whose registered office is at 37 Carr Lane, Hull, HU1 3RE. |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-04-06 19:31:16
|
I think I need a log file to identify where the script failed. But I am not able to get a header as recommended. I am getting this error: Global symbol "$system" requires explicit package name at ./tester-a line 7. Execution of ./tester-a aborted due to compilation errors. I am trying to use the header suggestion by Don but I am just not able to get it to work, #!/usr/bin/perl use strict; use Expect; my $timeout = 60; my $header = "\n\n======= $system =======\n"; my @servers = qw( Solaris-host Solaris-host Solaris-host Solaris-host ); for my $server (@servers) { # do your thing with $server change_password($server); } sub change_password { my $system = shift; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@' . $system); $ssh->debug(1); $ssh->expect ( $timeout, [ qr/Password:/], [ qr/Are you sure you want to continue connecting \(yes\/no\)?/] ); if ($ssh->match() =~ m/Are you sure you want to continue connecting \(yes\/no\)?/ ) { $ssh->send("yes\r"); } elsif ($ssh->match() =~ m/Password:/ ) { $ssh->send("mycurrentpassword\n"); } $ssh->expect(60, '$'); $ssh->print_log_file($header); $ssh->send("su - root\n"); $ssh->expect(60, 'Password:'); $ssh->send("rootpassword\n"); $ssh->expect(60, '#'); $ssh->send("passwd amagana\n"); $ssh->expect(60, 'New Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, 'Re-enter new Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); $ssh->close(); } //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 -----Original Message----- From: ESRY JR., DON [mailto:de...@at...] Sent: Wednesday, April 01, 2015 10:45 AM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT; Matt Zagrabelny Cc: exp...@li... Subject: RE: [Expectperl-discuss] expect.pm not updating password You will need to expect multiple things and then check to see what you got and handle that. It has been a long time since I did this on solaris so I may have the order wrong... my $timeout = 60; $ssh->send("passwd amagana\n"); $ssh->expect( $timeout, [ qr/New Password/], [ qr/ Are you sure you want to continue connecting/] ); If ( $ssh->match() =~ m/New Password/ ) { $ssh->send("mynewpassword\n"); } elsif ($ssh->match() =~ m/ Are you sure you want to continue connecting/ ) { $ssh->send("yes\n"); # then here put in what you expect to get next such as "New Password" # then send it the response such as "mynewpassword\n" } # continue on with the rest of your script $ssh->expect(60, 'Re-enter new Password:'); -----Original Message----- From: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT [mailto:and...@us...] Sent: Wednesday, April 01, 2015 10:24 AM To: ESRY JR., DON; Matt Zagrabelny Cc: exp...@li... Subject: RE: [Expectperl-discuss] expect.pm not updating password Now that I have a working script and thanks very much to you Matt and Don, I am trying to put in my script an if else because sometimes my script will encounter this : Are you sure you want to continue connecting (yes/no)?') what I did create are some variables is this correct and may I see an example if statement so that the script can make a decision and keep going? use Expect; my $knownhost = $ssh->expect(60, 'Are you sure you want to continue connecting (yes/no)?'); my $answer = $ssh->send("yes\n"); my $filename = "/var/tmp/expect_script.log"; //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 -----Original Message----- From: ESRY JR., DON [mailto:de...@at...] Sent: Tuesday, March 31, 2015 4:16 PM To: Matt Zagrabelny; MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: RE: [Expectperl-discuss] expect.pm not updating password I think you will want a log file to identify where the script failed. I recommend that you take out the 'w' from the $ssh->log_file($filename, 'w'); so it will append to the file rather than over writing it for each server. And then put in some sort of header for each server, something like: my $header = "\n\n======= $system =======\n"; $ssh->print_log_file($header); Or if you prefer a separate file for each server, then my $filename = "/var/tmp/expect_script_". $system ".log"; little stuff like this can be very frustrating. -----Original Message----- From: Matt Zagrabelny [mailto:mzagrabe@d.umn.edu] Sent: Tuesday, March 31, 2015 4:56 PM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: Re: [Expectperl-discuss] expect.pm not updating password On Tue, Mar 31, 2015 at 3:37 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > Thank you Matt, > > I just don't know how to put it in a working way I learn by examples I > am a novice on perl and the modules. Maybe spend a day or two writing some basic perl programs so you feel more comfortable with this stuff. I'm sure there are truckloads of perl tutorials out there. I added some context below. You'll need to clean up the leading '>' characters. -m > > #!/usr/bin/perl > use strict; > > use Expect; > > # my @servers = qw( > # server1.example.net > # server2.example.net > # server3.example.net > # server4.example.net > # server5.example.net > # ); > # > # for my $server (@servers) { > # # do your thing with $server change_password($server); > # } > sub change_password { my $system = shift; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@' . $system); > $ssh->debug(1); > $ssh->log_file($filename, 'w'); > $ssh->expect(60, 'Password:'); > $ssh->send("mycurrentpassword\n"); > $ssh->expect(60, '$'); > $ssh->send("su - root\n"); > $ssh->expect(60, 'Password:'); > $ssh->send("myrootpassword\n"); > $ssh->expect(60, '#'); > $ssh->send("passwd amagana\n"); > $ssh->expect(60, 'New Password:'); > $ssh->send("mynewpassword\n"); > $ssh->expect(60, 'Re-enter new Password:'); > $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); > $ssh->send("exit\n"); $ssh->close(); } ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-04-06 19:00:29
|
Thank you, Your help got me here and I learned so much and there is much more to learn but I enjoy it. My script has a list of four Solaris 10 servers. Launching the perl expect.pm script from a Red Hat server it went to each box and changed my password with no problems. Thank you again. Here is the example script I used. #!/usr/bin/perl use strict; use Expect; my $timeout = 60; my @servers = qw( Solaris-host03 Solaris-host04 Solaris-host05 Solaris-host06 ); for my $server (@servers) { # do your thing with $server change_password($server); } sub change_password { my $system = shift; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@' . $system); #my $ssh = Expect->new('ssh amagana@tstorweb01'); $ssh->debug(1); $ssh->expect ( $timeout, [ qr/Password:/], [ qr/Are you sure you want to continue connecting \(yes\/no\)?/] ); if ($ssh->match() =~ m/Are you sure you want to continue connecting \(yes\/no\)?/ ) { $ssh->send("yes\r"); } elsif ($ssh->match() =~ m/Password:/ ) { $ssh->send("mycurrentpassword\n"); } $filename = "/var/tmp/expect_script_". $system ".log"; $ssh->expect(60, '$'); $ssh->send("su - root\n"); $ssh->expect(60, 'Password:'); $ssh->send("rootpassword\n"); $ssh->expect(60, '#'); $ssh->send("passwd amagana\n"); $ssh->expect(60, 'New Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, 'Re-enter new Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); $ssh->close(); } //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 -----Original Message----- From: ESRY JR., DON [mailto:de...@at...] Sent: Friday, April 03, 2015 3:19 PM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT; ope...@op... Cc: Matt Zagrabelny; mike nicholas Subject: RE: updating list of server account password It looks to me like it will work. There is NO WAY that I would run a password changing script without logging everything I did. I would suggest again that you log the results. You have that line commented out. And with the 'w' you will overwrite the log everytime you run that sub so it will only have the last server you run it on. I suggest that you take out the 'w'. With the 'w' everytime you call that sub it will wipe out the file. This means that when you one it for remotehost6 it will wipe out everything from remotehost5 So I recommend that you replace: #$ssh->log_file($filename, 'w'); With $ssh->log_file($filename); I also recommend that you put in a couple of exits; 1 to close the root shell and the other to close your login shell. If you prefer a safer test, try running the hostname command rather than the passwd command. $ssh->expect(60, '$'); $ssh->send("su - root\n"); $ssh->expect(60, 'Password:'); $ssh->send("rootpassword\n"); $ssh->expect(60, '#'); $ssh->send("hostname\n"); # you might want to leave this in anyway to make reading the log easier $ssh->expect(60, '#'); $ssh->send("uptime\n"); #$ssh->send("passwd amagana\n"); #$ssh->expect(60, 'New Password:'); #$ssh->send("mynewpassword\n"); #$ssh->expect(60, 'Re-enter new Password:'); #$ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); $ssh->send("exit\n"); $ssh->expect(60, '$'); $ssh->send("exit\n"); $ssh->close(); -----Original Message----- From: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT [mailto:and...@us...] Sent: Friday, April 03, 2015 3:53 PM To: ope...@op... Cc: ESRY JR., DON; Matt Zagrabelny; mike nicholas Subject: updating list of server account password Hello Mike, Don and Matt, At the point I am at this list of servers in my script I would really need someone with more experience to see if I even have the right scripting. #!/usr/bin/perl use strict; use Expect; my $timeout = 60; my @servers = qw( remotehost03 remotehost04 remotehost05 remotehost06 ); for my $server (@servers) { # do your thing with $server change_password($server); } sub change_password { my $system = shift; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@' . $system); $ssh->debug(1); $ssh->expect ( $timeout, [ qr/Password:/], [ qr/Are you sure you want to continue connecting \(yes\/no\)?/] ); if ($ssh->match() =~ m/Are you sure you want to continue connecting \(yes\/no\)?/ ) { $ssh->send("yes\r"); } elsif ($ssh->match() =~ m/Password:/ ) { $ssh->send("mypassword\n"); } #$ssh->log_file($filename, 'w'); $ssh->expect(60, '$'); $ssh->send("su - root\n"); $ssh->expect(60, 'Password:'); $ssh->send("rootpassword\n"); $ssh->expect(60, '#'); $ssh->send("passwd amagana\n"); $ssh->expect(60, 'New Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, 'Re-enter new Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); $ssh->close(); Respectfully, #!/usr/bin/perl use strict; use Expect; my $timeout = 60; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@remotehost'); $ssh->debug(1); $ssh->expect ( $timeout, [ qr/Password:/], [ qr/Are you sure you want to continue connecting \(yes\/no\)?/] ); if ($ssh->match() =~ m/Are you sure you want to continue connecting \(yes\/no\)?/ ) { $ssh->send("yes\r"); } elsif ($ssh->match() =~ m/Password:/ ) { $ssh->send("mypassword\n"); } #$ssh->log_file($filename, 'w'); $ssh->expect(60, '$'); $ssh->send("su - root\n"); $ssh->expect(60, 'Password:'); $ssh->send("rootpassword\n"); $ssh->expect(60, '#'); $ssh->send("passwd amagana\n"); $ssh->expect(60, 'New Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, 'Re-enter new Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); $ssh->close(); //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 -----Original Message----- From: mike nicholas [mailto:xmi...@gm...] Sent: Wednesday, April 01, 2015 9:46 AM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: ESRY JR., DON; Matt Zagrabelny; exp...@li... Subject: Re: [Expectperl-discuss] expect.pm not updating password Try something like this: my $exp = new Expect; $exp->log_stdout(1); $username = "XXXXXX"; $exp->spawn( "ssh -l ${username} ${ip} " ) or die "cannot spawn $command: $! \n"; $exp->log_file("./${log_dir}/$ip\_info.log"); print "\nspawning ssh connection to $ip on $time\n\n"; $exp->log_file->print( "\nspawning ssh connection to $ip on $time\n\n" ); $exp->expect(8, [ 'connecting' => sub { $exp->send("yes \n"); exp_continue; } ], [ 'assword:' => sub { $exp->send("$pw\n"); exp_continue; } ], [ '-re', '> ?$' => sub { break; }], [ 'try again' => sub { die " died from bad password.\n"; }], [ 'refused' => sub { die " died from connection refused.\n"; exp_continue; } ], [ eof => sub { die " died from eof.\n"; }], [ timeout => sub { $exp->hard_close(); }], ); On Wed, Apr 1, 2015 at 9:24 AM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: Now that I have a working script and thanks very much to you Matt and Don, I am trying to put in my script an if else because sometimes my script will encounter this : Are you sure you want to continue connecting (yes/no)?') what I did create are some variables is this correct and may I see an example if statement so that the script can make a decision and keep going? use Expect; my $knownhost = $ssh->expect(60, 'Are you sure you want to continue connecting (yes/no)?'); my $answer = $ssh->send("yes\n"); my $filename = "/var/tmp/expect_script.log"; //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 <tel:%28405%29%20734-0341> -----Original Message----- From: ESRY JR., DON [mailto:de...@at...] Sent: Tuesday, March 31, 2015 4:16 PM To: Matt Zagrabelny; MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: RE: [Expectperl-discuss] expect.pm not updating password I think you will want a log file to identify where the script failed. I recommend that you take out the 'w' from the $ssh->log_file($filename, 'w'); so it will append to the file rather than over writing it for each server. And then put in some sort of header for each server, something like: my $header = "\n\n======= $system =======\n"; $ssh->print_log_file($header); Or if you prefer a separate file for each server, then my $filename = "/var/tmp/expect_script_". $system ".log"; little stuff like this can be very frustrating. -----Original Message----- From: Matt Zagrabelny [mailto:mzagrabe@d.umn.edu] Sent: Tuesday, March 31, 2015 4:56 PM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: Re: [Expectperl-discuss] expect.pm not updating password On Tue, Mar 31, 2015 at 3:37 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > Thank you Matt, > > I just don't know how to put it in a working way I learn by examples I > am a novice on perl and the modules. Maybe spend a day or two writing some basic perl programs so you feel more comfortable with this stuff. I'm sure there are truckloads of perl tutorials out there. I added some context below. You'll need to clean up the leading '>' characters. -m > > #!/usr/bin/perl > use strict; > > use Expect; > > # my @servers = qw( > # server1.example.net > # server2.example.net > # server3.example.net > # server4.example.net > # server5.example.net > # ); > # > # for my $server (@servers) { > # # do your thing with $server change_password($server); > # } > sub change_password { my $system = shift; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@' . $system); > $ssh->debug(1); > $ssh->log_file($filename, 'w'); > $ssh->expect(60, 'Password:'); > $ssh->send("mycurrentpassword\n"); > $ssh->expect(60, '$'); > $ssh->send("su - root\n"); > $ssh->expect(60, 'Password:'); > $ssh->send("myrootpassword\n"); > $ssh->expect(60, '#'); > $ssh->send("passwd amagana\n"); > $ssh->expect(60, 'New Password:'); > $ssh->send("mynewpassword\n"); > $ssh->expect(60, 'Re-enter new Password:'); > $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); > $ssh->send("exit\n"); $ssh->close(); } ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-04-03 19:17:39
|
Hello Mike, At the point I am at this list of servers in my script I would really need someone with more experience to see if I even have the right scripting. #!/usr/bin/perl use strict; use Expect; my $timeout = 60; my @servers = qw( remotehost03 remotehost04 remotehost05 remotehost06 ); for my $server (@servers) { # do your thing with $server change_password($server); } sub change_password { my $system = shift; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@' . $system); $ssh->debug(1); $ssh->expect ( $timeout, [ qr/Password:/], [ qr/Are you sure you want to continue connecting \(yes\/no\)?/] ); if ($ssh->match() =~ m/Are you sure you want to continue connecting \(yes\/no\)?/ ) { $ssh->send("yes\r"); } elsif ($ssh->match() =~ m/Password:/ ) { $ssh->send("mypassword\n"); } #$ssh->log_file($filename, 'w'); $ssh->expect(60, '$'); $ssh->send("su - root\n"); $ssh->expect(60, 'Password:'); $ssh->send("rootpassword\n"); $ssh->expect(60, '#'); $ssh->send("passwd amagana\n"); $ssh->expect(60, 'New Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, 'Re-enter new Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); $ssh->close(); Respectfully, #!/usr/bin/perl use strict; use Expect; my $timeout = 60; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@remotehost'); $ssh->debug(1); $ssh->expect ( $timeout, [ qr/Password:/], [ qr/Are you sure you want to continue connecting \(yes\/no\)?/] ); if ($ssh->match() =~ m/Are you sure you want to continue connecting \(yes\/no\)?/ ) { $ssh->send("yes\r"); } elsif ($ssh->match() =~ m/Password:/ ) { $ssh->send("mypassword\n"); } #$ssh->log_file($filename, 'w'); $ssh->expect(60, '$'); $ssh->send("su - root\n"); $ssh->expect(60, 'Password:'); $ssh->send("rootpassword\n"); $ssh->expect(60, '#'); $ssh->send("passwd amagana\n"); $ssh->expect(60, 'New Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, 'Re-enter new Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); $ssh->close(); //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 -----Original Message----- From: mike nicholas [mailto:xmi...@gm...] Sent: Wednesday, April 01, 2015 9:46 AM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: ESRY JR., DON; Matt Zagrabelny; exp...@li... Subject: Re: [Expectperl-discuss] expect.pm not updating password Try something like this: my $exp = new Expect; $exp->log_stdout(1); $username = "XXXXXX"; $exp->spawn( "ssh -l ${username} ${ip} " ) or die "cannot spawn $command: $! \n"; $exp->log_file("./${log_dir}/$ip\_info.log"); print "\nspawning ssh connection to $ip on $time\n\n"; $exp->log_file->print( "\nspawning ssh connection to $ip on $time\n\n" ); $exp->expect(8, [ 'connecting' => sub { $exp->send("yes \n"); exp_continue; } ], [ 'assword:' => sub { $exp->send("$pw\n"); exp_continue; } ], [ '-re', '> ?$' => sub { break; }], [ 'try again' => sub { die " died from bad password.\n"; }], [ 'refused' => sub { die " died from connection refused.\n"; exp_continue; } ], [ eof => sub { die " died from eof.\n"; }], [ timeout => sub { $exp->hard_close(); }], ); On Wed, Apr 1, 2015 at 9:24 AM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: Now that I have a working script and thanks very much to you Matt and Don, I am trying to put in my script an if else because sometimes my script will encounter this : Are you sure you want to continue connecting (yes/no)?') what I did create are some variables is this correct and may I see an example if statement so that the script can make a decision and keep going? use Expect; my $knownhost = $ssh->expect(60, 'Are you sure you want to continue connecting (yes/no)?'); my $answer = $ssh->send("yes\n"); my $filename = "/var/tmp/expect_script.log"; //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 <tel:%28405%29%20734-0341> -----Original Message----- From: ESRY JR., DON [mailto:de...@at...] Sent: Tuesday, March 31, 2015 4:16 PM To: Matt Zagrabelny; MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: RE: [Expectperl-discuss] expect.pm not updating password I think you will want a log file to identify where the script failed. I recommend that you take out the 'w' from the $ssh->log_file($filename, 'w'); so it will append to the file rather than over writing it for each server. And then put in some sort of header for each server, something like: my $header = "\n\n======= $system =======\n"; $ssh->print_log_file($header); Or if you prefer a separate file for each server, then my $filename = "/var/tmp/expect_script_". $system ".log"; little stuff like this can be very frustrating. -----Original Message----- From: Matt Zagrabelny [mailto:mzagrabe@d.umn.edu] Sent: Tuesday, March 31, 2015 4:56 PM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: Re: [Expectperl-discuss] expect.pm not updating password On Tue, Mar 31, 2015 at 3:37 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > Thank you Matt, > > I just don't know how to put it in a working way I learn by examples I > am a novice on perl and the modules. Maybe spend a day or two writing some basic perl programs so you feel more comfortable with this stuff. I'm sure there are truckloads of perl tutorials out there. I added some context below. You'll need to clean up the leading '>' characters. -m > > #!/usr/bin/perl > use strict; > > use Expect; > > # my @servers = qw( > # server1.example.net > # server2.example.net > # server3.example.net > # server4.example.net > # server5.example.net > # ); > # > # for my $server (@servers) { > # # do your thing with $server change_password($server); > # } > sub change_password { my $system = shift; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@' . $system); > $ssh->debug(1); > $ssh->log_file($filename, 'w'); > $ssh->expect(60, 'Password:'); > $ssh->send("mycurrentpassword\n"); > $ssh->expect(60, '$'); > $ssh->send("su - root\n"); > $ssh->expect(60, 'Password:'); > $ssh->send("myrootpassword\n"); > $ssh->expect(60, '#'); > $ssh->send("passwd amagana\n"); > $ssh->expect(60, 'New Password:'); > $ssh->send("mynewpassword\n"); > $ssh->expect(60, 'Re-enter new Password:'); > $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); > $ssh->send("exit\n"); $ssh->close(); } ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-04-03 18:41:03
|
Hello Mike, I am a little lost with how would I have my list of servers work in my script since now I have a working if elsif statement in my script. You see I have different groups of servers for example for testing, development and production. Would it be better to have my script read from a file or files that contain the list of my servers? I am a novice and need some help with some examples. Respectfully, #!/usr/bin/perl use strict; use Expect; my $timeout = 60; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@remotehost'); $ssh->debug(1); $ssh->expect ( $timeout, [ qr/Password:/], [ qr/Are you sure you want to continue connecting \(yes\/no\)?/] ); if ($ssh->match() =~ m/Are you sure you want to continue connecting \(yes\/no\)?/ ) { $ssh->send("yes\r"); } elsif ($ssh->match() =~ m/Password:/ ) { $ssh->send("mypassword\n"); } #$ssh->log_file($filename, 'w'); $ssh->expect(60, '$'); $ssh->send("su - root\n"); $ssh->expect(60, 'Password:'); $ssh->send("rootpassword\n"); $ssh->expect(60, '#'); $ssh->send("passwd amagana\n"); $ssh->expect(60, 'New Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, 'Re-enter new Password:'); $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); $ssh->close(); //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 -----Original Message----- From: mike nicholas [mailto:xmi...@gm...] Sent: Wednesday, April 01, 2015 9:46 AM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: ESRY JR., DON; Matt Zagrabelny; exp...@li... Subject: Re: [Expectperl-discuss] expect.pm not updating password Try something like this: my $exp = new Expect; $exp->log_stdout(1); $username = "XXXXXX"; $exp->spawn( "ssh -l ${username} ${ip} " ) or die "cannot spawn $command: $! \n"; $exp->log_file("./${log_dir}/$ip\_info.log"); print "\nspawning ssh connection to $ip on $time\n\n"; $exp->log_file->print( "\nspawning ssh connection to $ip on $time\n\n" ); $exp->expect(8, [ 'connecting' => sub { $exp->send("yes \n"); exp_continue; } ], [ 'assword:' => sub { $exp->send("$pw\n"); exp_continue; } ], [ '-re', '> ?$' => sub { break; }], [ 'try again' => sub { die " died from bad password.\n"; }], [ 'refused' => sub { die " died from connection refused.\n"; exp_continue; } ], [ eof => sub { die " died from eof.\n"; }], [ timeout => sub { $exp->hard_close(); }], ); On Wed, Apr 1, 2015 at 9:24 AM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: Now that I have a working script and thanks very much to you Matt and Don, I am trying to put in my script an if else because sometimes my script will encounter this : Are you sure you want to continue connecting (yes/no)?') what I did create are some variables is this correct and may I see an example if statement so that the script can make a decision and keep going? use Expect; my $knownhost = $ssh->expect(60, 'Are you sure you want to continue connecting (yes/no)?'); my $answer = $ssh->send("yes\n"); my $filename = "/var/tmp/expect_script.log"; //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 <tel:%28405%29%20734-0341> -----Original Message----- From: ESRY JR., DON [mailto:de...@at...] Sent: Tuesday, March 31, 2015 4:16 PM To: Matt Zagrabelny; MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: RE: [Expectperl-discuss] expect.pm not updating password I think you will want a log file to identify where the script failed. I recommend that you take out the 'w' from the $ssh->log_file($filename, 'w'); so it will append to the file rather than over writing it for each server. And then put in some sort of header for each server, something like: my $header = "\n\n======= $system =======\n"; $ssh->print_log_file($header); Or if you prefer a separate file for each server, then my $filename = "/var/tmp/expect_script_". $system ".log"; little stuff like this can be very frustrating. -----Original Message----- From: Matt Zagrabelny [mailto:mzagrabe@d.umn.edu] Sent: Tuesday, March 31, 2015 4:56 PM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: Re: [Expectperl-discuss] expect.pm not updating password On Tue, Mar 31, 2015 at 3:37 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > Thank you Matt, > > I just don't know how to put it in a working way I learn by examples I > am a novice on perl and the modules. Maybe spend a day or two writing some basic perl programs so you feel more comfortable with this stuff. I'm sure there are truckloads of perl tutorials out there. I added some context below. You'll need to clean up the leading '>' characters. -m > > #!/usr/bin/perl > use strict; > > use Expect; > > # my @servers = qw( > # server1.example.net > # server2.example.net > # server3.example.net > # server4.example.net > # server5.example.net > # ); > # > # for my $server (@servers) { > # # do your thing with $server change_password($server); > # } > sub change_password { my $system = shift; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@' . $system); > $ssh->debug(1); > $ssh->log_file($filename, 'w'); > $ssh->expect(60, 'Password:'); > $ssh->send("mycurrentpassword\n"); > $ssh->expect(60, '$'); > $ssh->send("su - root\n"); > $ssh->expect(60, 'Password:'); > $ssh->send("myrootpassword\n"); > $ssh->expect(60, '#'); > $ssh->send("passwd amagana\n"); > $ssh->expect(60, 'New Password:'); > $ssh->send("mynewpassword\n"); > $ssh->expect(60, 'Re-enter new Password:'); > $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); > $ssh->send("exit\n"); $ssh->close(); } ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-04-03 15:22:12
|
Okay it works so far and thank you for the help and guidance I have re-read your e-mail about the if elsif statement and I have put it in this way in my script my next goal is to try to have a list or read from different lists of servers. Thank you again so very much getting this far with me. #!/usr/bin/perl use strict; use Expect; my $timeout = 60; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@remotehost'); $ssh->debug(1); $ssh->expect ( $timeout, [ qr/Password:/], [ qr/Are you sure you want to continue connecting \(yes\/no\)?/] ); if ($ssh->match() =~ m/Are you sure you want to continue connecting \(yes\/no\)?/ ) { $ssh->send("yes\r"); } elsif ($ssh->match() =~ m/Password:/ ) { $ssh->send("mypassword)^\n"); } This is my output from the debugging: Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0xa310c0)', 60, 'ARRAY(0x6e6a00)', 'ARRAY(0x6e6a50)') called at ./tester-a line 9 The authenticity of host 'remotehost (x.x.x.x)' can't be established. RSA key fingerprint is x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x. Are you sure you want to continue connecting (yes/no)? Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0xa310c0)', 60, 'Password:') called at ./tester-a line 22 yes Warning: Permanently added 'remotehost,x.x.x.x' (RSA) to the list of known hosts. Password: Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0xa310c0)', 60, '$') called at ./tester-a line 25 \e[01m[\u@\h \W ]\e[m $ Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0xa310c0)', 60, 'Password:') called at ./tester-a line 27 su - root Password: Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0xa310c0)', 60, '#') called at ./tester-a line 29 root@remotehost #Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0xa310c0)', 60, 'New Password:') called at ./tester-a line 31 passwd amagana New Password: Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0xa310c0)', 60, 'Re-enter new Password:') called at ./tester-a line 33 Re-enter new Password: Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0xa310c0)', 60, '#') called at ./tester-a line 35 passwd: password successfully changed for amagana root@remotehost #Closing spawn id(3). at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0xa310c0)') called at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0xa310c0)') called at ./tester-a line 0 eval {...} called at ./tester-a line 0 Pid 7475 of spawn id(3) terminated, Status: 0xFF00 //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 -----Original Message----- From: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Sent: Friday, April 03, 2015 9:24 AM To: 'ESRY JR., DON'; Matt Zagrabelny Cc: exp...@li... Subject: RE: [Expectperl-discuss] expect.pm not updating password Hello Don, I was away from my if elsif and tried modifying my script but so far it is not sending the yes after I get the question Are you sure you want to continue connecting (yes/no)? This my script with debugging on. use Expect; my $timeout = 60; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@remotehost'); $ssh->debug(1); if ($ssh->match() =~ m/Are you sure you want to continue connecting \(yes\/no\)?/ ) { $ssh->send("yes\r"); } elsif ( $ssh->match() =~ m/Password:/ ) { $ssh->send("mypassword\n"); } This my output I get so far from the debugging it just sits at Are you sure. Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0x174b2db0)', 60, 'Password:') called at ./tester-a line 21 The authenticity of host 'remotehost (0.0.0.0)' can't be established. RSA key fingerprint is x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x. Are you sure you want to continue connecting (yes/no)? //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 -----Original Message----- From: ESRY JR., DON [mailto:de...@at...] Sent: Wednesday, April 01, 2015 10:45 AM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT; Matt Zagrabelny Cc: exp...@li... Subject: RE: [Expectperl-discuss] expect.pm not updating password You will need to expect multiple things and then check to see what you got and handle that. It has been a long time since I did this on solaris so I may have the order wrong... my $timeout = 60; $ssh->send("passwd amagana\n"); $ssh->expect( $timeout, [ qr/New Password/], [ qr/ Are you sure you want to continue connecting/] ); If ( $ssh->match() =~ m/New Password/ ) { $ssh->send("mynewpassword\n"); } elsif ($ssh->match() =~ m/ Are you sure you want to continue connecting/ ) { $ssh->send("yes\n"); # then here put in what you expect to get next such as "New Password" # then send it the response such as "mynewpassword\n" } # continue on with the rest of your script $ssh->expect(60, 'Re-enter new Password:'); -----Original Message----- From: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT [mailto:and...@us...] Sent: Wednesday, April 01, 2015 10:24 AM To: ESRY JR., DON; Matt Zagrabelny Cc: exp...@li... Subject: RE: [Expectperl-discuss] expect.pm not updating password Now that I have a working script and thanks very much to you Matt and Don, I am trying to put in my script an if else because sometimes my script will encounter this : Are you sure you want to continue connecting (yes/no)?') what I did create are some variables is this correct and may I see an example if statement so that the script can make a decision and keep going? use Expect; my $knownhost = $ssh->expect(60, 'Are you sure you want to continue connecting (yes/no)?'); my $answer = $ssh->send("yes\n"); my $filename = "/var/tmp/expect_script.log"; //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 -----Original Message----- From: ESRY JR., DON [mailto:de...@at...] Sent: Tuesday, March 31, 2015 4:16 PM To: Matt Zagrabelny; MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: RE: [Expectperl-discuss] expect.pm not updating password I think you will want a log file to identify where the script failed. I recommend that you take out the 'w' from the $ssh->log_file($filename, 'w'); so it will append to the file rather than over writing it for each server. And then put in some sort of header for each server, something like: my $header = "\n\n======= $system =======\n"; $ssh->print_log_file($header); Or if you prefer a separate file for each server, then my $filename = "/var/tmp/expect_script_". $system ".log"; little stuff like this can be very frustrating. -----Original Message----- From: Matt Zagrabelny [mailto:mzagrabe@d.umn.edu] Sent: Tuesday, March 31, 2015 4:56 PM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: Re: [Expectperl-discuss] expect.pm not updating password On Tue, Mar 31, 2015 at 3:37 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > Thank you Matt, > > I just don't know how to put it in a working way I learn by examples I > am a novice on perl and the modules. Maybe spend a day or two writing some basic perl programs so you feel more comfortable with this stuff. I'm sure there are truckloads of perl tutorials out there. I added some context below. You'll need to clean up the leading '>' characters. -m > > #!/usr/bin/perl > use strict; > > use Expect; > > # my @servers = qw( > # server1.example.net > # server2.example.net > # server3.example.net > # server4.example.net > # server5.example.net > # ); > # > # for my $server (@servers) { > # # do your thing with $server change_password($server); > # } > sub change_password { my $system = shift; my $filename = "/var/tmp/expect_script.log"; my $ssh = Expect->new('ssh amagana@' . $system); > $ssh->debug(1); > $ssh->log_file($filename, 'w'); > $ssh->expect(60, 'Password:'); > $ssh->send("mycurrentpassword\n"); > $ssh->expect(60, '$'); > $ssh->send("su - root\n"); > $ssh->expect(60, 'Password:'); > $ssh->send("myrootpassword\n"); > $ssh->expect(60, '#'); > $ssh->send("passwd amagana\n"); > $ssh->expect(60, 'New Password:'); > $ssh->send("mynewpassword\n"); > $ssh->expect(60, 'Re-enter new Password:'); > $ssh->send("mynewpassword\n"); $ssh->expect(60, '#'); > $ssh->send("exit\n"); $ssh->close(); } ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |