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: uday <udh...@gm...> - 2013-09-15 16:25:29
|
*Hi perl experts,* *I'm pretty new to perl expect and passing commands to client server and printing execution status in terminal. If you look at my output, I am executing “*cat /etc/redhat-release” but actual execution happens at the end of code and prints the output at the end of execution. I would like to get actual execution of “cat /etc/redhat-release” output displayed in terminal after “TERMINAL: cat /etc/redhat-release” output. Could you please help me to fix ASAP? Highly appreciated for early reply. * * * **INPUT FILE:* * ** [root@server-1 ~]# cat "cs3.csv"* *192.18.16.19,root,conley,cat /etc/redhat-release,ls,date* * [root@server-1 ~]#* * * *OUTPUT:* [root@server-1 ~]# perl temp4.pl Testcase no:1 ++++++++++++++++++++++++++++ Test case details: 192.18.16.19,root,conley,cat /etc/redhat-release,ls,date Logged into 192.18.16.19 root@192.18.16.19's password: Last login: Sat Sep 14 02:31:25 2013 from server-1.lss.emc.com TERMINAL: cat /etc/redhat-release TERMINAL: ls TERMINAL: date [root@client197 ~]# [root@client197 ~]# [root@client197 ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.9 (Tikanga) [root@client197 ~]# [root@client197 ~]# ls anaconda-ks.cfg install.log test.txt Desktop install.log.syslog LINUX-5.7.1.00.00-029.RHEL5.x86_64.rpm SSL [root@client197 ~]# [root@client197 ~]# date Sun Sep 15 04:23:42 EDT 2013 [root@client197 ~]# exit logout Connection to 192.18.16.19 closed. *ACTUAL CODE:* [root@server-1 ~]# cat /perlupdate/test/csv/temp4.pl #!/usr/bin/perl use Expect; use warnings; #use strict; $timestamp = getLoggingTime(); $l_file = "/perlupdate/test/csv/log/$timestamp.log"; # Use the open() function to create the file. unless(open FILE, '>' .$l_file) { # Die with error message # if we can't open it. die "\nUnable to create $l_file\n"; } close (FILE); my $file = "cs3.csv"; open(my $data, '<', $file) or die "Could not open '$file' $!\n"; my $lnnum = 0; while (my $line = <$data>) { $exp=new Expect; $exp->send("\r"); $lnnum++; print "\n"; print "Testcase no:$lnnum \n"; print "++++++++++++++++++++++++++++ \n"; print "\n"; print "Test case details: $line\n"; print "\n"; chomp $line; my @fields = split "," , $line; $exp-> raw_pty(1); #eliminates echo back to expect $exp-> log_file("$l_file"); $exp-> debug(0); $exp->spawn("ssh $fields[0] -l $fields[1]") or die "Cannot connect $fields[0]: $!\n"; print"Logged into $fields[0]\n"; $exp->expect(10, "password"); $exp->send("$fields[2]\r"); $exp->expect(30, "Last"); $exp->send("\r"); $i=3; while($i <= $#fields) { print "\n"; print"TERMINAL: $fields[$i]\n"; $exp->send("\r"); $exp->send("$fields[$i]\r"); print "\n"; $i++; } $exp->send("exit\r"); #$exp->send("\r") $exp->soft_close(); } sub getLoggingTime { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); my $nice_timestamp = sprintf ( "%04d_%02d_%02d_%02d_%02d_%02d", $year+1900,$mon+1,$mday,$hour,$min,$sec); return $nice_timestamp; } [root@server-1 ~]# -- Cheers Udhaya.D |
From: Erich K. <wav...@gm...> - 2013-06-02 12:27:20
|
http://freevoicepbx.com/kafyc/loj.tecygdsjz |
From: Bryan B. <br...@bu...> - 2013-02-15 14:38:01
|
I've written an autoexpect.pl, well not really. Its a hack that runs the real autoexpect, then parses the resulting script and converts it to perl. Ugly I know, but it works ok. The one problem I have is that I would like to capture window size and bake it into the script, as some expecting seems to be affected by this. For example: when I run say: ./autoexpect.pl man man, do something like <space><space>1Gq, the resulting script hangs when you get to 1G because the pager is sending characters based on window size. I can $exp->slave()->clone_winsize_from(*STDIN) as long as its ran from the same window it was created. But I dont really know how to store STDIN size info, and reproduce it on a new Expect object called in a different environment. Anyway, here you go: --> #!/usr/bin/perl # # Autoexpect conversion tool (tcl => perl) # use strict; # Globals my $expect_script = "script.pl"; my $autoexpect_script = "script.exp"; # Values for the expect script being created my $log_file = undef; my $log_stdout = 1; # Usage statement if ( ! @ARGV ) { print "Usage: $0 [autoexpect flags] <program>\n"; exit(-1); } # Doesnt work without the real deal my $autoexpect = `which autoexpect`; chomp $autoexpect; if ( ! stat($autoexpect) ) { print "Error: you must have the real autoexpect for this to work\n"; exit(-1); } # Launch the real autoexpect my $return = system("$autoexpect -f $autoexpect_script @ARGV"); if ($return != 0 ) { print "Warning: autoexpect seems to have failed with code: $return\n"; } # Parse the resulting script, convert it to perl, and write that to file open(AUTOEXPECT, "$autoexpect_script") or die "Error: autoexpect script missing: $autoexpect_script\n"; open(PROG, ">$expect_script") or die "Error: could not open $expect_script for writing: $!\n"; print PROG "#!/usr/bin/perl use strict; use Expect; my \$exp = new Expect; \$exp->log_stdout($log_stdout); "; print PROG "\$exp->log_file(\"$log_file\", \"w\");\n" if $log_file; print PROG "\n"; my $last_match = 256; # max size of the expect match string while (<AUTOEXPECT>) { if ( m/^spawn (.*)$/ ) { my $program = $1; print PROG "\$exp->spawn(\"$program\");\n\n"; next; } if ( m/^sleep (.*)$/ ) { my $sleep = $1; print PROG "select(undef, undef, undef, $sleep);\n"; next; } if ( m/^send .* \"(.*)\"$/ ) { my $string = $1; print PROG "\$exp->clear_accum();\n"; print PROG "\$exp->send(\"$string\");\n"; next; } # Only matching the last line of the expect match string if ( m/^expect .exact \"(.*)\"$/ ) { my $string = $1; $string = substr($string, -$last_match) if length($string) > $last_match; print PROG "\$exp->expect(undef, \"$string\");\n"; next; } elsif ( m/^(.*)\"$/ ) { my $string = $1; $string = substr($string, -$last_match) if length($string) > $last_match; print PROG "\$exp->expect(undef, \"$string\");\n"; next; } } close(AUTOEXPECT); print PROG "\n"; print PROG "\$exp->hard_close();\n"; print PROG "\n"; close(PROG); <-- Bryan Bueter |
From: Keith C. <kei...@ya...> - 2012-07-09 20:55:06
|
Sent from my iPad On Jul 9, 2012, at 3:42 PM, Atahualpa Ledesma <ata...@gm...> wrote: > I'm trying to automate something using Perl and Expect.pm using a virtual serial port on an HP server using ILO3, but somehow when i try to start a virtual console from Expect created pty, it just freezes there, and doesn't start, but if i do it manually via ssh then it works, i think it is an stty/pty issue but i don't know where to start debugging this. > > This is a simpler version of what i am doing: > > #!/usr/bin/perl > use strict; > use warnings; > use Expect; > > my $iloip = "1.2.3.4"; # IP changed to protect the guilty > my $ilouser = "Administrator"; > my $ilopswd = "mypass"; #same > my $osuser = "admin"; > my $ospassword = "SecurePassword!"; #same > > my $expect = Expect->new(); > $expect->log_stdout(1); #debug > $expect->exp_internal(1); #debug > $expect->spawn("ssh $ilouser\@$iloip"); > $expect->expect(10, "ssword:"); > $expect->send("$ilopswd\n"); > $expect->expect(10, "iLO->"); > $expect->send("vsp\n"); > $expect->expect(20, "login:"); > ..... > > After issuing the vsp command, i should get a login prompt ( on the server there is a console configuration on /etc/inittab using agetty [co:2345:respawn:/sbin/agetty ttyS0 115200 vt102] ) but nothing happens. > > If i do the same commands on a manually initiated ssh session then it works correctly > > Example: > > Script output: > > [dev@dev-ipdr-01 standalone]$ perl rconsole.pl > Spawned 'ssh Administrator@1.2.3.4' > spawn id(3) > Pid: 27108 > Tty: /dev/pts/0 > at /usr/share/perl5/vendor_perl/Expect.pm line 181 > Expect::spawn('Expect=GLOB(0x19ad360)', 'ssh Administrator@1.2.3.4') called at rconsole.pl line 15 > Starting EXPECT pattern matching... > at /usr/share/perl5/vendor_perl/Expect.pm line 561 > Expect::expect('Expect=GLOB(0x19ad360)', 10, 'ssword:') called at rconsole.pl line 16 > spawn id(3): list of patterns: > #1: -ex `ssword:' > > spawn id(3): Does `' > match: > pattern #1: -ex `ssword:'? No. > > Administrator@1.2.3.4's password: > spawn id(3): Does `Administrator@1.2.3.4\'s password: ' > match: > pattern #1: -ex `ssword:'? YES!! > Before match string: `Administrator@1.2.3.4\'s pa' > Match string: `ssword:' > After match string: ` ' > Matchlist: () > Sending 'mypass\n' to spawn id(3) > at /usr/share/perl5/vendor_perl/Expect.pm line 1264 > Expect::print('Expect=GLOB(0x19ad360)', 'mypass!\x{a}') called at rconsole.pl line 17 > Starting EXPECT pattern matching... > at /usr/share/perl5/vendor_perl/Expect.pm line 561 > Expect::expect('Expect=GLOB(0x19ad360)', 10, 'iLO->') called at rconsole.pl line 18 > spawn id(3): list of patterns: > #1: -ex `iLO->' > > spawn id(3): Does ` ' > match: > pattern #1: -ex `iLO->'? No. > > spawn id(3): Does ` \r\n' > match: > pattern #1: -ex `iLO->'? No. > > User:Administrator logged-in to > spawn id(3): Does ` \r\nUser:Administrator logged-in to ' > match: > pattern #1: -ex `iLO->'? No. > > ilo1.solutions.net(1.2.3.4) > iLO 3 Advanced 1.28 at Jan 13 2012 > Server Name: FOOBAR > Server Power: On > > </>hpiLO-> > spawn id(3): Does ` \r\nUser:Administrator logged-in to ilo1.solutions.net(1.2.3.4)\r\niLO 3 Advanced 1.28 at Jan 13 2012\r\nServer Name: FOOBAR\r\nServer Power: On\r\n\n</>hpiLO-> ' > match: > pattern #1: -ex `iLO->'? YES!! > Before match string: ` \r\nUser:Administrator logged-in to ilo1.solutions.net(1.2.3.4)\r\niLO 3 Advanced 1.28 at Jan 13 2012\r\nServer Name: FOOBAR\r\nServer Power: On\r\n\n</>hp' > Match string: `iLO->' > After match string: ` ' > Matchlist: () > Sending 'vsp\n' to spawn id(3) > at /usr/share/perl5/vendor_perl/Expect.pm line 1264 > Expect::print('Expect=GLOB(0x19ad360)', 'vsp\x{a}') called at rconsole.pl line 19 > Starting EXPECT pattern matching... > at /usr/share/perl5/vendor_perl/Expect.pm line 561 > Expect::expect('Expect=GLOB(0x19ad360)', 20, 'login:') called at rconsole.pl line 20 > spawn id(3): list of patterns: > #1: -ex `login:' > > > spawn id(3): Does ` ' > match: > pattern #1: -ex `login:'? No. > > vsp > > spawn id(3): Does ` vsp\n' > match: > pattern #1: -ex `login:'? No. > > [dev@dev-ipdr-01 standalone]$ > > > Now this is the output of a manual ssh connection: > > dev@dev-ipdr-01 standalone]$ ssh Administrator@1.2.3.4 > Administrator@10.2.3.4's password: > User:Administrator logged-in to ilo1.solutions.net(1.2.3.4) > iLO 3 Advanced 1.28 at Jan 13 2012 > Server Name: FOOBAR > Server Power: On > > </>hpiLO-> vsp > > Virtual Serial Port Active: COM1 > > Starting virtual serial port. > Press 'ESC (' to return to the CLI Session. > > > > foobar.foo.myboxen.lan login: > > > -END- > > I tried to see the stty options on the ssh connection's pty and the Expect spawn'ed pty: > > SSH PTY: > > [dev@dev-ipdr-01 ~]$ stty -F /dev/pts/2 > speed 38400 baud; line = 0; > eol = M-^?; eol2 = M-^?; lnext = <undef>; min = 1; time = 0; > -icrnl > -icanon -echo > > EXPECT IO::Pty PTY: > > [dev@dev-ipdr-01 ~]$ stty -F /dev/pts/0 > speed 38400 baud; line = 0; > min = 1; time = 0; > -brkint -icrnl -imaxbel > -opost > -isig -icanon -iexten -echo -echoe -echok > > > > How can i debug this? Is there anyway to see if there is something in the pty settings that ILO is setting up? > > > > -- > -------------------------------------------------- > Atahualpa Ledesma > Redhat Certified Engineer > Oracle Certified Professional 9i > Unix/Linux/Oracle Consultant > ata...@gm... > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |
From: Atahualpa L. <ata...@gm...> - 2012-07-09 20:42:46
|
I'm trying to automate something using Perl and Expect.pm using a virtual serial port on an HP server using ILO3, but somehow when i try to start a virtual console from Expect created pty, it just freezes there, and doesn't start, but if i do it manually via ssh then it works, i think it is an stty/pty issue but i don't know where to start debugging this. This is a simpler version of what i am doing: #!/usr/bin/perl use strict; use warnings; use Expect; my $iloip = "1.2.3.4"; # IP changed to protect the guilty my $ilouser = "Administrator"; my $ilopswd = "mypass"; #same my $osuser = "admin"; my $ospassword = "SecurePassword!"; #same my $expect = Expect->new(); $expect->log_stdout(1); #debug $expect->exp_internal(1); #debug $expect->spawn("ssh $ilouser\@$iloip"); $expect->expect(10, "ssword:"); $expect->send("$ilopswd\n"); $expect->expect(10, "iLO->"); $expect->send("vsp\n"); $expect->expect(20, "login:"); ..... After issuing the vsp command, i should get a login prompt ( on the server there is a console configuration on /etc/inittab using agetty [co:2345:respawn:/sbin/agetty ttyS0 115200 vt102] ) but nothing happens. If i do the same commands on a manually initiated ssh session then it works correctly Example: Script output: [dev@dev-ipdr-01 standalone]$ perl rconsole.pl Spawned 'ssh Administrator@1.2.3.4' spawn id(3) Pid: 27108 Tty: /dev/pts/0 at /usr/share/perl5/vendor_perl/Expect.pm line 181 Expect::spawn('Expect=GLOB(0x19ad360)', 'ssh Administrator@1.2.3.4') called at rconsole.pl line 15 Starting EXPECT pattern matching... at /usr/share/perl5/vendor_perl/Expect.pm line 561 Expect::expect('Expect=GLOB(0x19ad360)', 10, 'ssword:') called at rconsole.pl line 16 spawn id(3): list of patterns: #1: -ex `ssword:' spawn id(3): Does `' match: pattern #1: -ex `ssword:'? No. Administrator@1.2.3.4's password: spawn id(3): Does `Administrator@1.2.3.4\'s password: ' match: pattern #1: -ex `ssword:'? YES!! Before match string: `Administrator@1.2.3.4\'s pa' Match string: `ssword:' After match string: ` ' Matchlist: () Sending 'mypass\n' to spawn id(3) at /usr/share/perl5/vendor_perl/Expect.pm line 1264 Expect::print('Expect=GLOB(0x19ad360)', 'mypass!\x{a}') called at rconsole.pl line 17 Starting EXPECT pattern matching... at /usr/share/perl5/vendor_perl/Expect.pm line 561 Expect::expect('Expect=GLOB(0x19ad360)', 10, 'iLO->') called at rconsole.plline 18 spawn id(3): list of patterns: #1: -ex `iLO->' spawn id(3): Does ` ' match: pattern #1: -ex `iLO->'? No. spawn id(3): Does ` \r\n' match: pattern #1: -ex `iLO->'? No. User:Administrator logged-in to spawn id(3): Does ` \r\nUser:Administrator logged-in to ' match: pattern #1: -ex `iLO->'? No. ilo1.solutions.net(1.2.3.4) iLO 3 Advanced 1.28 at Jan 13 2012 Server Name: FOOBAR Server Power: On </>hpiLO-> spawn id(3): Does ` \r\nUser:Administrator logged-in to ilo1.solutions.net(1.2.3.4)\r\niLO 3 Advanced 1.28 at Jan 13 2012\r\nServer Name: FOOBAR\r\nServer Power: On\r\n\n</>hpiLO-> ' match: pattern #1: -ex `iLO->'? YES!! Before match string: ` \r\nUser:Administrator logged-in to ilo1.solutions.net(1.2.3.4)\r\niLO 3 Advanced 1.28 at Jan 13 2012\r\nServer Name: FOOBAR\r\nServer Power: On\r\n\n</>hp' Match string: `iLO->' After match string: ` ' Matchlist: () Sending 'vsp\n' to spawn id(3) at /usr/share/perl5/vendor_perl/Expect.pm line 1264 Expect::print('Expect=GLOB(0x19ad360)', 'vsp\x{a}') called at rconsole.plline 19 Starting EXPECT pattern matching... at /usr/share/perl5/vendor_perl/Expect.pm line 561 Expect::expect('Expect=GLOB(0x19ad360)', 20, 'login:') called at rconsole.plline 20 spawn id(3): list of patterns: #1: -ex `login:' spawn id(3): Does ` ' match: pattern #1: -ex `login:'? No. vsp spawn id(3): Does ` vsp\n' match: pattern #1: -ex `login:'? No. [dev@dev-ipdr-01 standalone]$ Now this is the output of a manual ssh connection: dev@dev-ipdr-01 standalone]$ ssh Administrator@1.2.3.4 Administrator@10.2.3.4's password: User:Administrator logged-in to ilo1.solutions.net(1.2.3.4) iLO 3 Advanced 1.28 at Jan 13 2012 Server Name: FOOBAR Server Power: On </>hpiLO-> vsp Virtual Serial Port Active: COM1 Starting virtual serial port. Press 'ESC (' to return to the CLI Session. foobar.foo.myboxen.lan login: -END- I tried to see the stty options on the ssh connection's pty and the Expect spawn'ed pty: SSH PTY: [dev@dev-ipdr-01 ~]$ stty -F /dev/pts/2 speed 38400 baud; line = 0; eol = M-^?; eol2 = M-^?; lnext = <undef>; min = 1; time = 0; -icrnl -icanon -echo EXPECT IO::Pty PTY: [dev@dev-ipdr-01 ~]$ stty -F /dev/pts/0 speed 38400 baud; line = 0; min = 1; time = 0; -brkint -icrnl -imaxbel -opost -isig -icanon -iexten -echo -echoe -echok How can i debug this? Is there anyway to see if there is something in the pty settings that ILO is setting up? -- -------------------------------------------------- Atahualpa Ledesma Redhat Certified Engineer<https://www.redhat.com/wapps/training/certification/verify.html?certNumber=111-189-312&verify=Verify> Oracle Certified Professional 9i Unix/Linux/Oracle Consultant ata...@gm... |
From: Bryan B. <br...@bu...> - 2012-04-17 12:13:53
|
> > > > ----- Original Message ----- >> From: Bryan Bueter <br...@bu...> >> To: exp...@li... >> Cc: >> Sent: Monday, April 16, 2012 9:20 PM >> Subject: [Expectperl-discuss] Yet Another Threading Example >> >> Ok, still playing around with threading on top of Expect, and I've >> designed what I think is a pretty good solution. However there is much >> I >> dont understand and I'm looking for feedback to make sure i'm not doing >> something inherently wrong. >> >> The way I've been able to do this is by pre-allocating pty's for jobs >> I'm >> going to need, in this case i'm ssh'ing so i need one pty per host. >> >> After the pty's are set up, i fork off one or more worker process who >> reads in a list of command from a pipe. When the worker gets a hostname >> it then forks another process who ties STDIN/OUT/ERR to the pty for that >> host and exec's the ssh command. > > Have you considered using Net::OpenSSH or Net::OpenSSH::Parallel? > > I'm not really trying to execute a parallel ssh, i'm trying to use expect within a thread. The example was arbitrary, you could Expect any command you wanted in this way. I'm simply looking for technical concerns related to the implementation. For example, in the "try" script bundled with IO::Tty, the parent process "syncs" with the exec by using a pipe: --> pipe(STAT_RDR, STAT_WTR) or die "Cannot open pipe: $!"; STAT_WTR->autoflush(1); $pid = fork(); die "Cannot fork" if not defined $pid; unless ($pid) { ... # Set up STDIN/OUT/ERR stuff { exec(@ARGV) }; print STAT_WTR $!+0; die "Cannot exec(@ARGV): $!"; } close STAT_WTR; $pty->close_slave(); $pty->set_raw(); # now wait for child exec (eof due to close-on-exit) or exec error my $errstatus = sysread(STAT_RDR, $errno, 256); die "Cannot sync with child: $!" if not defined $errstatus; close STAT_RDR; <-- I dont do any kind of sync in my example. Is that an issue? It doesnt appear to cause me any grief however I'm not sure what happens when I read from $pty before the child finishes setting it up. Thanks Bryan Bueter |
From: Salvador F. <sfa...@ya...> - 2012-04-17 08:16:28
|
----- Original Message ----- > From: Bryan Bueter <br...@bu...> > To: exp...@li... > Cc: > Sent: Monday, April 16, 2012 9:20 PM > Subject: [Expectperl-discuss] Yet Another Threading Example > > Ok, still playing around with threading on top of Expect, and I've > designed what I think is a pretty good solution. However there is much I > dont understand and I'm looking for feedback to make sure i'm not doing > something inherently wrong. > > The way I've been able to do this is by pre-allocating pty's for jobs > I'm > going to need, in this case i'm ssh'ing so i need one pty per host. > > After the pty's are set up, i fork off one or more worker process who > reads in a list of command from a pipe. When the worker gets a hostname > it then forks another process who ties STDIN/OUT/ERR to the pty for that > host and exec's the ssh command. Have you considered using Net::OpenSSH or Net::OpenSSH::Parallel? |
From: Bryan B. <br...@bu...> - 2012-04-16 20:00:23
|
Ok, still playing around with threading on top of Expect, and I've designed what I think is a pretty good solution. However there is much I dont understand and I'm looking for feedback to make sure i'm not doing something inherently wrong. The way I've been able to do this is by pre-allocating pty's for jobs I'm going to need, in this case i'm ssh'ing so i need one pty per host. After the pty's are set up, i fork off one or more worker process who reads in a list of command from a pipe. When the worker gets a hostname it then forks another process who ties STDIN/OUT/ERR to the pty for that host and exec's the ssh command. The main process controls the threading and manages the workers. In my example i dont do much error checking at all, but in the even the thread returned a bad result, i could probably HUP the worker process and have it destroy its child. That way i dont loose a worker when its child process hangs. Anyway, here is my code, please let me know what you think. Thanks Bryan Bueter --> #!/usr/bin/perl use strict; use threads; use IO::Pty; use Expect; $Expect::Log_Stdout = 0; my $prompt = '[>#\$] $'; my @hosts = ("host1", "host2", "host3", "host4", "host5", "host6", "host7", "host8", "host9"); # Aliases to localhost my @commands = ("uptime", "who", "who am i", "pwd"); # Pre-allocate ptys my %ptys = (); foreach (@hosts) { $ptys{$_} = new IO::Pty; } # Start worker processes my @workers = (); my $workers = 4; for (my $i=0; $i<$workers; $i++) { pipe(my $from_parent, my $to_child); unless(fork()) { close($to_child); worker($from_parent); } close($from_parent); push(@workers, $to_child); } # Scan and feed worker processes hosts to spawn ssh sessions my @threads; while (@hosts) { for (my $i=0; $i<@workers; $i++) { if ( !defined($threads[$i]) || $threads[$i]->is_joinable() ) { $threads[$i]->join() if defined($threads[$i]); my $host = shift @hosts; print { $workers[$i] } $host."\n"; $ptys{$host}->close_slave(); $ptys{$host}->set_raw(); $threads[$i] = threads->new("run_threaded", $host); last; } } } # Out of hosts join everyone back in and clean up foreach (@threads) { $_->join(); } foreach (@workers) { close $_ ; } wait(); ## END OF MAIN ### # Expect on the pty and run the @commands sub run_threaded { my $host = shift; my $exp = Expect->exp_init($ptys{$host}); $exp->log_file("$host.log"); $exp->expect(5, '-re', $prompt) or return 0; foreach (@commands) { print "Executing $_ on $host\n"; $exp->send($_."\n"); $exp->expect(5, '-re', $prompt) or return 0; } $exp->send("exit;\nexit;\n;exit;\n"); $exp->hard_close(); return 1; } # Worker waits for hostnames and spawns the ssh command sub worker { my $pipe = shift; while (<$pipe>) { chomp; my $host = $_; unless(fork()) { my $pty = $ptys{$host}; $pty->make_slave_controlling_terminal(); my $slave = $pty->slave(); close($pty); $slave->clone_winsize_from(\*STDIN); $slave->set_raw(); open(STDIN, "<&". $slave->fileno()); open(STDOUT, ">&". $slave->fileno()); open(STDERR, ">&". $slave->fileno()); close($slave); { exec("ssh -o StrictHostKeyChecking=no -x $host"); } die "Cannot exec ssh: $!"; } wait(); } exit(0); } <-- |
From: Arunmozhi G. <aru...@gm...> - 2012-02-18 17:32:53
|
How do I telnet to a Cisco router and then connect to the console of each device through a serial line and run commands ?. FYI, I have configured serial async ports on my router. My objective is to connect to each serial line and configure the ip address and then run some commands. How do I do that ? Any idea ?. Thanks Arun |
From: Madrigal, J. A <j.m...@mi...> - 2011-10-11 17:29:23
|
Thanks! $exp->exp_internal(1); Doing the job! -Juan On 10/11/11 12:09 PM, "Roland Giersig" <rgi...@cp...> wrote: >$Expect::Exp_Internal = 1; > >;-) > >2011/10/11 Madrigal, Juan A <j.m...@mi...>: >> Hi Salvador, >> >> You are right it is doing nothing. I removed the telnet code and I end >>up >> with the same result. Looks like I don't need telnet at all. >> >> I'm trying to automate an Xterm session by passing commands with >>expect. I >> was under the impression that telnet was needed >> because that¹s how the clients connect manually. >> >> $exp->log_user(1) >> >> Doesn't seem to be doing anything. Strange. >> >> Thanks! >> Juan >> >> >> On 10/11/11 10:55 AM, "Salvador Fandino" <sfa...@ya...> wrote: >> >>> >>> >>> >>> >>>----- Original Message ----- >>>> From: "Madrigal, Juan A" <j.m...@mi...> >>>> To: Salvador Fandino <sfa...@ya...> >>>> Cc: Matt Zagrabelny <mzagrabe@d.umn.edu> >>>> Sent: Tuesday, October 11, 2011 4:39 PM >>>> Subject: Re: [Expectperl-discuss] Connecting: Net::OpenSSH -> >>>>Net::Telnet -> Expect.pm >>>> >>>>T hanks for the help! >>>> >>>> I have it working as follows now: >>>> >>>> use Net::OpenSSH; >>>> use Net::Telnet (); >>>> use Expect; >>>> >>>> >>>> # open ssh connection >>>> $ssh = Net::OpenSSH->new($host, user => $user, passwd => $passwd); >>>> $ssh->error and die "unable to connect to remote server: ". >>>> $ssh->error; >>>> >>>> my ($pty, $pid) = $ssh->open2pty(); >>>> >>>> >>>> # open telnet connection over ssh >>>> my $tlc = Net::Telnet->new(fhopen => $pty); >>> >>>Are you sure you need to use Net::Telnet? It is doing nothing here. >>> >>>You are just connecting to the server in $host via ssh and then running >>>a >>>shell there that gets finally connected to the Expect object. Is that >>>what you want (from your previous mail I though you wanted to connect to >>>a second server via telnet)? >>> >>>> # pass connection to expect >>>> my $exp = Expect->init($tlc); >>>> $exp->raw_pty(0); >>>> $exp->debug(3); >>>> >>>> >>>> Now the only thing is left is figuring out how to "see" what expect is >>>> doing or get some feed back >>>> on stdout and later I'll need to figure out how to use SSH Keys vs >>>> user/passwd combo as well. >>>> >>>> It seems like my expect code is running, but I can't confirm. Flying >>>>blind. >>>> >>>> The only thing that I notice is that I can throw in an >>>>$exp->interact(); >>>> and the result of the last command is spit out to stdout. Though I'm >>>> pretty sure there's a better way to see whats going on while expect >>>>code >>>> runs. >>>> >>>> Suggestions? >>> >>>try using... >>> >>> $expect->log_user(1) >>> >>>> >>>> Thanks, >>>> Juan >>>> >>>> >>>> >>>> On 10/11/11 1:55 AM, "Salvador Fandino" <sfa...@ya...> >>>> wrote: >>>> >>>>> >>>>>> From: "Madrigal, Juan A" <j.m...@mi...> >>>>>> To: "exp...@li..." >>>>>> <exp...@li...> >>>>>> Sent: Monday, October 10, 2011 8:35 PM >>>>>> Subject: [Expectperl-discuss] Connecting: Net::OpenSSH -> >>>>>>Net::Telnet >>>> -> >>>>>> Expect.pm >>>>>> >>>>>> Hi, >>>>>> >>>>>> I'm new to using expect.pm and I'm have trouble trying to create >>>> an ssh >>>>>> tunnel with telnet in the middle then passing expect commands. >>>>>> >>>>>> I.E. >>>>>> Net::OpenSSH -> Net::Telnet -> Expect.pm >>>>>> >>>>>> >>>>> >>>>> If telnet is installed on the SSH gateway, you can use... >>>>> >>>>> my $ssh = Net::OpenSSH->new(...); >>>>> my ($pty, $pid) = $ssh->open2pty(telnet => $host) >>>>> or die "unable to telnet to $host: " . $ssh->error; >>>>> my $expect = Expect->init($pty); >>>>> ... >>>> >> >> >> >>------------------------------------------------------------------------- >>----- >> All the data continuously generated in your IT infrastructure contains a >> definitive record of customers, application performance, security >> threats, fraudulent activity and more. Splunk takes this data and makes >> sense of it. Business sense. IT sense. Common sense. >> http://p.sf.net/sfu/splunk-d2d-oct >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> |
From: Roland G. <rgi...@cp...> - 2011-10-11 16:09:11
|
$Expect::Exp_Internal = 1; ;-) 2011/10/11 Madrigal, Juan A <j.m...@mi...>: > Hi Salvador, > > You are right it is doing nothing. I removed the telnet code and I end up > with the same result. Looks like I don't need telnet at all. > > I'm trying to automate an Xterm session by passing commands with expect. I > was under the impression that telnet was needed > because that¹s how the clients connect manually. > > $exp->log_user(1) > > Doesn't seem to be doing anything. Strange. > > Thanks! > Juan > > > On 10/11/11 10:55 AM, "Salvador Fandino" <sfa...@ya...> wrote: > >> >> >> >> >>----- Original Message ----- >>> From: "Madrigal, Juan A" <j.m...@mi...> >>> To: Salvador Fandino <sfa...@ya...> >>> Cc: Matt Zagrabelny <mzagrabe@d.umn.edu> >>> Sent: Tuesday, October 11, 2011 4:39 PM >>> Subject: Re: [Expectperl-discuss] Connecting: Net::OpenSSH -> >>>Net::Telnet -> Expect.pm >>> >>>T hanks for the help! >>> >>> I have it working as follows now: >>> >>> use Net::OpenSSH; >>> use Net::Telnet (); >>> use Expect; >>> >>> >>> # open ssh connection >>> $ssh = Net::OpenSSH->new($host, user => $user, passwd => $passwd); >>> $ssh->error and die "unable to connect to remote server: ". >>> $ssh->error; >>> >>> my ($pty, $pid) = $ssh->open2pty(); >>> >>> >>> # open telnet connection over ssh >>> my $tlc = Net::Telnet->new(fhopen => $pty); >> >>Are you sure you need to use Net::Telnet? It is doing nothing here. >> >>You are just connecting to the server in $host via ssh and then running a >>shell there that gets finally connected to the Expect object. Is that >>what you want (from your previous mail I though you wanted to connect to >>a second server via telnet)? >> >>> # pass connection to expect >>> my $exp = Expect->init($tlc); >>> $exp->raw_pty(0); >>> $exp->debug(3); >>> >>> >>> Now the only thing is left is figuring out how to "see" what expect is >>> doing or get some feed back >>> on stdout and later I'll need to figure out how to use SSH Keys vs >>> user/passwd combo as well. >>> >>> It seems like my expect code is running, but I can't confirm. Flying >>>blind. >>> >>> The only thing that I notice is that I can throw in an $exp->interact(); >>> and the result of the last command is spit out to stdout. Though I'm >>> pretty sure there's a better way to see whats going on while expect code >>> runs. >>> >>> Suggestions? >> >>try using... >> >> $expect->log_user(1) >> >>> >>> Thanks, >>> Juan >>> >>> >>> >>> On 10/11/11 1:55 AM, "Salvador Fandino" <sfa...@ya...> >>> wrote: >>> >>>> >>>>> From: "Madrigal, Juan A" <j.m...@mi...> >>>>> To: "exp...@li..." >>>>> <exp...@li...> >>>>> Sent: Monday, October 10, 2011 8:35 PM >>>>> Subject: [Expectperl-discuss] Connecting: Net::OpenSSH -> Net::Telnet >>> -> >>>>> Expect.pm >>>>> >>>>> Hi, >>>>> >>>>> I'm new to using expect.pm and I'm have trouble trying to create >>> an ssh >>>>> tunnel with telnet in the middle then passing expect commands. >>>>> >>>>> I.E. >>>>> Net::OpenSSH -> Net::Telnet -> Expect.pm >>>>> >>>>> >>>> >>>> If telnet is installed on the SSH gateway, you can use... >>>> >>>> my $ssh = Net::OpenSSH->new(...); >>>> my ($pty, $pid) = $ssh->open2pty(telnet => $host) >>>> or die "unable to telnet to $host: " . $ssh->error; >>>> my $expect = Expect->init($pty); >>>> ... >>> > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2d-oct > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: Madrigal, J. A <j.m...@mi...> - 2011-10-11 15:17:29
|
On 10/11/11 10:39 AM, "Madrigal, Juan A" <j.m...@mi...> wrote: >Thanks for the help! > >I have it working as follows now: > >use Net::OpenSSH; >use Net::Telnet (); >use Expect; > > ># open ssh connection >$ssh = Net::OpenSSH->new($host, user => $user, passwd => $passwd); >$ssh->error and die "unable to connect to remote server: ". $ssh->error; > >my ($pty, $pid) = $ssh->open2pty(); > > ># open telnet connection over ssh >my $tlc = Net::Telnet->new(fhopen => $pty); > ># pass connection to expect >my $exp = Expect->init($tlc); >$exp->raw_pty(0); >$exp->debug(3); > > >Now the only thing is left is figuring out how to "see" what expect is >doing or get some feed back >on stdout and later I'll need to figure out how to use SSH Keys vs >user/passwd combo as well. > >It seems like my expect code is running, but I can't confirm. Flying >blind. > >The only thing that I notice is that I can throw in an $exp->interact(); >and the result of the last command is spit out to stdout. Though I'm >pretty sure there's a better way to see whats going on while expect code >runs. > >Suggestions? > >Thanks, >Juan > > > >On 10/11/11 1:55 AM, "Salvador Fandino" <sfa...@ya...> wrote: > >> >>>From: "Madrigal, Juan A" <j.m...@mi...> >>>To: "exp...@li..." >>><exp...@li...> >>>Sent: Monday, October 10, 2011 8:35 PM >>>Subject: [Expectperl-discuss] Connecting: Net::OpenSSH -> Net::Telnet -> >>>Expect.pm >>> >>>Hi, >>> >>>I'm new to using expect.pm and I'm have trouble trying to create an ssh >>>tunnel with telnet in the middle then passing expect commands. >>> >>>I.E. >>>Net::OpenSSH -> Net::Telnet -> Expect.pm >>> >>> >> >>If telnet is installed on the SSH gateway, you can use... >> >> my $ssh = Net::OpenSSH->new(...); >> my ($pty, $pid) = $ssh->open2pty(telnet => $host) >> or die "unable to telnet to $host: " . $ssh->error; >> my $expect = Expect->init($pty); >> ... > |
From: Madrigal, J. A <j.m...@mi...> - 2011-10-11 15:17:02
|
Hi Salvador, You are right it is doing nothing. I removed the telnet code and I end up with the same result. Looks like I don't need telnet at all. I'm trying to automate an Xterm session by passing commands with expect. I was under the impression that telnet was needed because that¹s how the clients connect manually. $exp->log_user(1) Doesn't seem to be doing anything. Strange. Thanks! Juan On 10/11/11 10:55 AM, "Salvador Fandino" <sfa...@ya...> wrote: > > > > >----- Original Message ----- >> From: "Madrigal, Juan A" <j.m...@mi...> >> To: Salvador Fandino <sfa...@ya...> >> Cc: Matt Zagrabelny <mzagrabe@d.umn.edu> >> Sent: Tuesday, October 11, 2011 4:39 PM >> Subject: Re: [Expectperl-discuss] Connecting: Net::OpenSSH -> >>Net::Telnet -> Expect.pm >> >>T hanks for the help! >> >> I have it working as follows now: >> >> use Net::OpenSSH; >> use Net::Telnet (); >> use Expect; >> >> >> # open ssh connection >> $ssh = Net::OpenSSH->new($host, user => $user, passwd => $passwd); >> $ssh->error and die "unable to connect to remote server: ". >> $ssh->error; >> >> my ($pty, $pid) = $ssh->open2pty(); >> >> >> # open telnet connection over ssh >> my $tlc = Net::Telnet->new(fhopen => $pty); > >Are you sure you need to use Net::Telnet? It is doing nothing here. > >You are just connecting to the server in $host via ssh and then running a >shell there that gets finally connected to the Expect object. Is that >what you want (from your previous mail I though you wanted to connect to >a second server via telnet)? > >> # pass connection to expect >> my $exp = Expect->init($tlc); >> $exp->raw_pty(0); >> $exp->debug(3); >> >> >> Now the only thing is left is figuring out how to "see" what expect is >> doing or get some feed back >> on stdout and later I'll need to figure out how to use SSH Keys vs >> user/passwd combo as well. >> >> It seems like my expect code is running, but I can't confirm. Flying >>blind. >> >> The only thing that I notice is that I can throw in an $exp->interact(); >> and the result of the last command is spit out to stdout. Though I'm >> pretty sure there's a better way to see whats going on while expect code >> runs. >> >> Suggestions? > >try using... > > $expect->log_user(1) > >> >> Thanks, >> Juan >> >> >> >> On 10/11/11 1:55 AM, "Salvador Fandino" <sfa...@ya...> >> wrote: >> >>> >>>> From: "Madrigal, Juan A" <j.m...@mi...> >>>> To: "exp...@li..." >>>> <exp...@li...> >>>> Sent: Monday, October 10, 2011 8:35 PM >>>> Subject: [Expectperl-discuss] Connecting: Net::OpenSSH -> Net::Telnet >> -> >>>> Expect.pm >>>> >>>> Hi, >>>> >>>> I'm new to using expect.pm and I'm have trouble trying to create >> an ssh >>>> tunnel with telnet in the middle then passing expect commands. >>>> >>>> I.E. >>>> Net::OpenSSH -> Net::Telnet -> Expect.pm >>>> >>>> >>> >>> If telnet is installed on the SSH gateway, you can use... >>> >>> my $ssh = Net::OpenSSH->new(...); >>> my ($pty, $pid) = $ssh->open2pty(telnet => $host) >>> or die "unable to telnet to $host: " . $ssh->error; >>> my $expect = Expect->init($pty); >>> ... >> |
From: Matt Z. <mzagrabe@d.umn.edu> - 2011-10-10 21:42:11
|
On Mon, Oct 10, 2011 at 1:35 PM, Madrigal, Juan A <j.m...@mi...> wrote: > Hi, > > I'm new to using expect.pm and I'm have trouble trying to create an ssh tunnel with telnet in the middle then passing expect commands. > > I.E. > Net::OpenSSH -> Net::Telnet -> Expect.pm Can you create the script on the ssh host such that you have: client% ssh sshhost /some/path/perl-script-that-does-expect That might get the Net::OpenSSH out of the equation. -mz |
From: Madrigal, J. A <j.m...@mi...> - 2011-10-10 19:09:30
|
Hi, I'm new to using expect.pm and I'm have trouble trying to create an ssh tunnel with telnet in the middle then passing expect commands. I.E. Net::OpenSSH -> Net::Telnet -> Expect.pm I'm trying to connect to the Innopac/Millenium Telnet interface to automate report creation. Any help would be appreciated! Thanks! Juan |
From: Alex H. <ale...@gm...> - 2011-07-13 06:19:49
|
Hi list, I figured this out. Turned out to be host was sending 'Re-enter new Password' as the prompt with an upper case P and seems no matter how many times I looked at it I couldn't see the typo. Best regards, Alex On 10 July 2011 22:26, Alex Harvey <ale...@gm...> wrote: > Hi list, > > I am trying to write my first Expect Perl script and have run into a wall > and wonder if someone can help. > > The script is supposed to connect to the console of a Solaris firewall, > enter the existing password, change the password to a new one, and then > logout and disconnect. > > Here is the code, which is based on the example from the CPAN home page: > > #!/usr/bin/perl > > use warnings; > use strict; > > use Expect; > > my $exp = Expect->spawn("./emulate_console.sh") > or die "Cannot spawn command: $!\n"; > my $spawn_ok; > > my $newpass = 'YYYYYYYY'; > > $exp->expect( > 10, > [ > qr/for help.*$/ => sub { > $spawn_ok = 1; > my $fh = shift; > $fh->send("\r"); > exp_continue; > } > ], > [ > qr/login: $/ => sub { > $spawn_ok = 1; > my $fh = shift; > $fh->send("root\r"); > exp_continue; > } > ], > [ > qr/Password: $/ => sub { > $spawn_ok = 1; > my $fh = shift; > $fh->send("XXXXXXXX\r"); # send the current password > exp_continue; > } > ], > [ > eof => sub { > if ($spawn_ok) { > die "ERROR: premature EOF in login.\n"; > } else { > die "ERROR: could not spawn console.\n"; > } > } > ], > [ > timeout => sub { > die "No login.\n"; > } > ], > '-re', qr/# $/, # wait for shell prompt, then exit expect > ); > $exp->send("passwd root\r"); > $exp->expect( > 10, > [ > qr/New Password: $/ => sub { > my $fh = shift; > $fh->send("$newpass\r"); > exp_continue; > } > ], > [ > qr/Re-enter new password: $/ => sub { > my $fh = shift; > $fh->send("$newpass\r"); > exp_continue; > } > ], > ); > $exp->send("\cD"); # logout > $exp->send("\cEc."); # key sequence to disconnect from console > > Now emulate_console.sh is just a simple shell script that pretends to be > the server and prints the same text to the screen as the server's console > would. This shell script is not the issue, as I get more or less the same > result using the real server. > > The result I get is this: > > It logs in fine, and issues the 'passwd root' command. It sends the new > password and then sends it a second time at the 'Re-enter new password' > prompt. Then it just mysteriously stops. When using the emulate_terminal.sh > script, that script never sends any further output to the screen once the > second password is sent (which means I never see the root prompt that should > follow this). I get more or less the same result when I use the real server. > > I am pulling my hair out now so any hints would be most appreciated. Also > some example code would be much appreciated (as can probably be seen I > really don't know what I am doing. :) > > Best regards, > Alex Harvey > |
From: Alex H. <ale...@gm...> - 2011-07-10 12:26:21
|
Hi list, I am trying to write my first Expect Perl script and have run into a wall and wonder if someone can help. The script is supposed to connect to the console of a Solaris firewall, enter the existing password, change the password to a new one, and then logout and disconnect. Here is the code, which is based on the example from the CPAN home page: #!/usr/bin/perl use warnings; use strict; use Expect; my $exp = Expect->spawn("./emulate_console.sh") or die "Cannot spawn command: $!\n"; my $spawn_ok; my $newpass = 'YYYYYYYY'; $exp->expect( 10, [ qr/for help.*$/ => sub { $spawn_ok = 1; my $fh = shift; $fh->send("\r"); exp_continue; } ], [ qr/login: $/ => sub { $spawn_ok = 1; my $fh = shift; $fh->send("root\r"); exp_continue; } ], [ qr/Password: $/ => sub { $spawn_ok = 1; my $fh = shift; $fh->send("XXXXXXXX\r"); # send the current password exp_continue; } ], [ eof => sub { if ($spawn_ok) { die "ERROR: premature EOF in login.\n"; } else { die "ERROR: could not spawn console.\n"; } } ], [ timeout => sub { die "No login.\n"; } ], '-re', qr/# $/, # wait for shell prompt, then exit expect ); $exp->send("passwd root\r"); $exp->expect( 10, [ qr/New Password: $/ => sub { my $fh = shift; $fh->send("$newpass\r"); exp_continue; } ], [ qr/Re-enter new password: $/ => sub { my $fh = shift; $fh->send("$newpass\r"); exp_continue; } ], ); $exp->send("\cD"); # logout $exp->send("\cEc."); # key sequence to disconnect from console Now emulate_console.sh is just a simple shell script that pretends to be the server and prints the same text to the screen as the server's console would. This shell script is not the issue, as I get more or less the same result using the real server. The result I get is this: It logs in fine, and issues the 'passwd root' command. It sends the new password and then sends it a second time at the 'Re-enter new password' prompt. Then it just mysteriously stops. When using the emulate_terminal.sh script, that script never sends any further output to the screen once the second password is sent (which means I never see the root prompt that should follow this). I get more or less the same result when I use the real server. I am pulling my hair out now so any hints would be most appreciated. Also some example code would be much appreciated (as can probably be seen I really don't know what I am doing. :) Best regards, Alex Harvey |
From: Jo R. <jr...@ne...> - 2011-07-06 05:56:05
|
So in case anyone is interested in the answer, it appears \b means "x0B" or "vertical tab" in ascii. I was able to match it with either \013 (octal) or \x0b (hex) On Jul 5, 2011, at 3:20 PM, Jo Rhett wrote: >> On Tue, Jul 5, 2011 at 3:32 PM, Jo Rhett <jr...@ne...> wrote: >>> I'm seeing a scenario where talking with an Accedian NID unit I receive \b >>> in the output from the unit. Unfortunately \b means "word boundary" in perl >>> regex-land. How can I match this character? (it is a single character and >>> not two) > > On Jul 5, 2011, at 2:07 PM, Matt Zagrabelny wrote: >> It's been a while since I've Expect-ed, but here is an off the cuff idea: >> s/[\000-\037]/ /g > > > Good idea. Curiosity -- any way to know how the debug output chooses to represent characters? Is \b likely to mean \011 or some such? How about if I wanted to match the exact character? I only see it in the exp_internal() output... > > -- > Jo Rhett > Net Consonance : consonant endings by net philanthropy, open source and other randomness > -- Jo Rhett Net Consonance : consonant endings by net philanthropy, open source and other randomness |
From: Jo R. <jr...@ne...> - 2011-07-05 22:20:55
|
> On Tue, Jul 5, 2011 at 3:32 PM, Jo Rhett <jr...@ne...> wrote: >> I'm seeing a scenario where talking with an Accedian NID unit I receive \b >> in the output from the unit. Unfortunately \b means "word boundary" in perl >> regex-land. How can I match this character? (it is a single character and >> not two) On Jul 5, 2011, at 2:07 PM, Matt Zagrabelny wrote: > It's been a while since I've Expect-ed, but here is an off the cuff idea: > s/[\000-\037]/ /g Good idea. Curiosity -- any way to know how the debug output chooses to represent characters? Is \b likely to mean \011 or some such? How about if I wanted to match the exact character? I only see it in the exp_internal() output... -- Jo Rhett Net Consonance : consonant endings by net philanthropy, open source and other randomness |
From: Matt Z. <mzagrabe@d.umn.edu> - 2011-07-05 21:09:28
|
On Tue, Jul 5, 2011 at 3:32 PM, Jo Rhett <jr...@ne...> wrote: > I'm seeing a scenario where talking with an Accedian NID unit I receive \b > in the output from the unit. Unfortunately \b means "word boundary" in perl > regex-land. How can I match this character? (it is a single character and > not two) It's been a while since I've Expect-ed, but here is an off the cuff idea: octal code? *goes and checks* I found the following reference: s/[\000-\037]/ /g at: http://www.perlmonks.org/?node_id=164831 You could use that as a starting point. -matt z |
From: Jo R. <jr...@ne...> - 2011-07-05 20:49:05
|
I'm seeing a scenario where talking with an Accedian NID unit I receive \b in the output from the unit. Unfortunately \b means "word boundary" in perl regex-land. How can I match this character? (it is a single character and not two) Problem: I don't know where in the string it will appear, so I can't simply use a wildcard at the appropriate point. I need to find and remove this string from the buffer. -- Jo Rhett Net Consonance : consonant endings by net philanthropy, open source and other randomness |
From: vijaya l. <vla...@ya...> - 2011-05-01 17:15:13
|
Hi, I am new to Perl and Expect. I am trying to spawn telnet to remote machine and trying to execute some command one by one after receiving the details of commands. Please explain me How $exp->send is working. When we send command to remote machine via $exp ->send, Is the output of command returns to this? If so, how much time it is taking to do this process.? Will there be any delay in $exp->send ? Please explain me.. |
From: vijaya l. <vla...@ya...> - 2011-05-01 17:03:36
|
vla...@ya... |
From: David Li <w.d...@gm...> - 2011-04-08 20:10:17
|
Hi Matt, Thanks the the link. I only want some basic stuff - sending CLI cmds and reading returns. I tried the simple example like this but the cmd execution hung with error messeages. No idea why. ---- script ------- use Net::Telnet::Cisco; my $router_addr = '172.27.122.88'; my $router_port = '2008'; my $session = Net::Telnet::Cisco->new(Host => $router_addr, Port => $router_port ); # $session->login('login', 'password'); # Execute a command my @output = $session->cmd('show version'); print @output; ------ execution ----- sjc-lds-545:perl$ ./cisco.pl Use of /g modifier is meaningless in split at /usr/cisco/packages/perl/perl-5.8.6/lib/site_perl/5.8.6/Net/Telnet/Cisco.pm line 756. Regards, David On Fri, Apr 8, 2011 at 11:22 AM, Matt Zagrabelny <mzagrabe@d.umn.edu> wrote: > You could use: > > http://search.cpan.org/~joshua/Net-Telnet-Cisco-1.10/Cisco.pm > > For some basic functionality. > > I've used Expect just fine with Cisco products, but there were issues > with threading. I've tried both Net::Telnet and Expect, but there were > still a couple issues. Now I just use Net::Telnet. > > -matt > > On Fri, Apr 8, 2011 at 12:19 PM, David Li <w.d...@gm...> wrote: > > Hi, Experts, > > I am new to Expect. Is there an example that > > uses both Net::Telnet and Expect to interact with Cisco routers? > > Regards, > > David > > > > > ------------------------------------------------------------------------------ > > Xperia(TM) PLAY > > It's a major breakthrough. An authentic gaming > > smartphone on the nation's most reliable network. > > And it wants your games. > > http://p.sf.net/sfu/verizon-sfdev > > _______________________________________________ > > Expectperl-discuss mailing list > > Exp...@li... > > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > > > > |
From: Matt Z. <mzagrabe@d.umn.edu> - 2011-04-08 18:24:10
|
You could use: http://search.cpan.org/~joshua/Net-Telnet-Cisco-1.10/Cisco.pm For some basic functionality. I've used Expect just fine with Cisco products, but there were issues with threading. I've tried both Net::Telnet and Expect, but there were still a couple issues. Now I just use Net::Telnet. -matt On Fri, Apr 8, 2011 at 12:19 PM, David Li <w.d...@gm...> wrote: > Hi, Experts, > I am new to Expect. Is there an example that > uses both Net::Telnet and Expect to interact with Cisco routers? > Regards, > David > > ------------------------------------------------------------------------------ > Xperia(TM) PLAY > It's a major breakthrough. An authentic gaming > smartphone on the nation's most reliable network. > And it wants your games. > http://p.sf.net/sfu/verizon-sfdev > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > |