From: schlum <jsc...@bo...> - 2007-07-11 14:19:52
|
Hi, I spent few days on this one, but couldn't get it working... I am working under sunOS bt1wxxxx#uname -a SunOS bt1wxxxx 5.6 Generic_105181-23 sun4u sparc SUNW,Ultra-60 I can run the following script without any problem : #!/usr/bin/perl use strict; use Expect; my $exp = Expect->new; $exp->raw_pty(1); my $test = $exp->spawn('/usr/local/bin/ssh', -l => 'my_user', 'my_host') or die "Cannot spawn command: $!\n"; my @test1 = $exp->expect(5,'-re','password:'); $exp->clear_accum(); my @test2 = $exp->send("my_pass\r\n"); my @test3 = $exp->expect(15,'-re','my_host'); my @test4 = $exp->send("sh privilege\r\n"); The last command is exectuted successfuly. But if I try this : #!/usr/bin/perl use strict; use Expect; use threads; use threads::shared; use Thread::Queue::Any; my $thread = threads->new(\&threadJob,); $thread->join; sub threadJob{ my $exp = Expect->new; $exp->raw_pty(1); my $test = $exp->spawn('/usr/local/bin/ssh', -l => 'my_user', 'my_host') or die "Cannot spawn command: $!\n"; my @test1 = $exp->expect(5,'-re','password:'); $exp->clear_accum(); my @test2 = $exp->send("my_pass\r\n"); my @test3 = $exp->expect(15,'-re','my_host'); my @test4 = $exp->send("sh privilege\r\n");# On envoie le mdp } I actually get connected, but Expect don't interact anymore with ssh after the logging. Instead, I can access the box, I telneted from STDIN ... Does anybody knows why I'm getting this strange behavior ? Btw, when I close the conection, the script finishes to run peacefully. -- View this message in context: http://www.nabble.com/Trouble-with-Expect-working-with-Threads-tf4062209.html#a11541250 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Matt Z. <mzagrabe@d.umn.edu> - 2007-07-11 16:45:18
|
[...] > Does anybody knows why I'm getting this strange behavior ? Check the archives. =46rom [1] comes: >> While Expect is supposed to be reasonably threadsafe, IO-Tty is *not*, that's where the problems come from. If you want to automate telnet, using Net::Telnet with Expect should be possible under threads. << I have had issues getting expect to use a spawned Net::Telnet object as well (which is "supposed to be" thread safe). After much gnashing of teeth, i have given up on Expect and been using Net::Telnet alone; which is disappointing, because Expect is much more powerful and elegant than Net::Telnet, however many *many* hours were wasted trying to get them to work together across a diverse population of Cisco gear. [1] http://sourceforge.net/mailarchive/message.php?msg_id=3D3DE0EEDC.7060703% 40cpan.org --=20 Matt Zagrabelny - mzagrabe@d.umn.edu - (218) 726 8844 University of Minnesota Duluth Information Technology Systems & Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot |
From: Austin S. <te...@of...> - 2007-07-11 19:01:55
|
On Wed, Jul 11, 2007 at 10:50:32AM -0500, Matt Zagrabelny wrote: > [...] > > > Does anybody knows why I'm getting this strange behavior ? > > Check the archives. > > From [1] comes: > > >> > While Expect is supposed to be reasonably threadsafe, IO-Tty is *not*, > that's where the problems come from. If you want to automate telnet, > using Net::Telnet with Expect should be possible under threads. > << > > I have had issues getting expect to use a spawned Net::Telnet object as > well (which is "supposed to be" thread safe). After much gnashing of > teeth, i have given up on Expect and been using Net::Telnet alone; which > is disappointing, because Expect is much more powerful and elegant than > Net::Telnet, however many *many* hours were wasted trying to get them to > work together across a diverse population of Cisco gear. > Have you tried using exp_init on a Net::Telnet object? That doesn't use IO::Tty. Austin |
From: Matt Z. <mzagrabe@d.umn.edu> - 2007-07-11 19:29:16
|
On Wed, 2007-07-11 at 11:56 -0700, Austin Schutz wrote: > On Wed, Jul 11, 2007 at 10:50:32AM -0500, Matt Zagrabelny wrote: > > [...] > >=20 > > > Does anybody knows why I'm getting this strange behavior ? > >=20 > > Check the archives. > >=20 > > From [1] comes: > >=20 > > >> > > While Expect is supposed to be reasonably threadsafe, IO-Tty is *not*, > > that's where the problems come from. If you want to automate telnet, > > using Net::Telnet with Expect should be possible under threads. > > << > >=20 > > I have had issues getting expect to use a spawned Net::Telnet object as > > well (which is "supposed to be" thread safe). After much gnashing of > > teeth, i have given up on Expect and been using Net::Telnet alone; whic= h > > is disappointing, because Expect is much more powerful and elegant than > > Net::Telnet, however many *many* hours were wasted trying to get them t= o > > work together across a diverse population of Cisco gear. > >=20 >=20 > Have you tried using exp_init on a Net::Telnet object? That doesn't > use IO::Tty. Yes, and by in large it worked. However, there were some Cisco switches that it did not work for. So... I emailed the list and a fellow gave me some good advice and my problems were solved, so I thought. There were still some anomalies that were not working correctly. So to recap: * Expect worked with everything, but no threads * Expect with Net::Telnet was threaded, but could not communicate to all switches * Expect with Net::Telnet plus trick from mailing list was able to communicate to almost all switches, but not all Hence... I now use Net::Telnet by itself. It is not as elegant as Expect, but the thread speedup is *awesome*. --=20 Matt Zagrabelny - mzagrabe@d.umn.edu - (218) 726 8844 University of Minnesota Duluth Information Technology Systems & Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot |
From: schlum <jsc...@bo...> - 2007-07-12 11:02:41
|
Matt Zagrabelny wrote: > > On Wed, 2007-07-11 at 11:56 -0700, Austin Schutz wrote: >> On Wed, Jul 11, 2007 at 10:50:32AM -0500, Matt Zagrabelny wrote: >> > [...] >> > >> > > Does anybody knows why I'm getting this strange behavior ? >> > >> > Check the archives. >> > >> > From [1] comes: >> > >> > >> >> > While Expect is supposed to be reasonably threadsafe, IO-Tty is *not*, >> > that's where the problems come from. If you want to automate telnet, >> > using Net::Telnet with Expect should be possible under threads. >> > << >> > >> > I have had issues getting expect to use a spawned Net::Telnet object as >> > well (which is "supposed to be" thread safe). After much gnashing of >> > teeth, i have given up on Expect and been using Net::Telnet alone; >> which >> > is disappointing, because Expect is much more powerful and elegant than >> > Net::Telnet, however many *many* hours were wasted trying to get them >> to >> > work together across a diverse population of Cisco gear. >> > >> >> Have you tried using exp_init on a Net::Telnet object? That doesn't >> use IO::Tty. > > Yes, and by in large it worked. However, there were some Cisco switches > that it did not work for. So... I emailed the list and a fellow gave me > some good advice and my problems were solved, so I thought. There were > still some anomalies that were not working correctly. So to recap: > > * Expect worked with everything, but no threads > > * Expect with Net::Telnet was threaded, but could not communicate to all > switches > > * Expect with Net::Telnet plus trick from mailing list was able to > communicate to almost all switches, but not all > > Hence... > > I now use Net::Telnet by itself. It is not as elegant as Expect, but the > thread speedup is *awesome*. > > -- > Matt Zagrabelny - mzagrabe@d.umn.edu - (218) 726 8844 > University of Minnesota Duluth > Information Technology Systems & Services > PGP key 1024D/84E22DA2 2005-11-07 > Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 > > He is not a fool who gives up what he cannot keep to gain what he cannot > lose. > -Jim Elliot > > Hi ! Thank you for your answers. Actually my need seems to be the same as you : I want to automatize some operations on routers/switch/... I have about 2500 boxes to manage => I need the multithreading in most cases. For me everything worked fine with expect/telnet/threaded, as for SNMP/threaded. But we are now desactivating the Telnet on the infrastructure, so I really need to find a remplacement to Telnet. Most Cisco equipments only support SSH V1, so the only way I found so far is to use Expect. You think there is no hope of getting Expect/SSH/threaded working ? What struck me (and let me some hope) is that the trouble appear with only one thread running... So far it's not a thread compatibily bug, no ? I haven't try yet to use exp_init, but I am not sure what FILEHANDLE I am suppose to feed it with. Is there a way to get a filehandle from a ssh conection in Perl ? Thank you very much for your help. Jerome -- View this message in context: http://www.nabble.com/Trouble-with-Expect-working-with-Threads-tf4062209.html#a11557709 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Roland G. <rgi...@cp...> - 2007-07-13 16:16:54
|
>From the perlthrtut: "Thinking of mixing fork() and threads? Please lie down and wait until the feeling passes." ;-) Note that spawn() does a fork. So this can only work if you spawn() all SSH connections in the main thread and then pass the Expect objects to the threads for handling. Bryan Bueter has provided a working example for using Expect/SSH/threads on the mailing list. Hope this helps, Roland PS: Net::SSH2 looks promising because it's objects are tied filehandles and thus should work with Expect via exp_init(). But I haven't had the time to try that yet. Hopefully any day soon... On 7/11/07, schlum <jsc...@bo...> wrote: > > Hi, > > I spent few days on this one, but couldn't get it working... > > I am working under sunOS > bt1wxxxx#uname -a > SunOS bt1wxxxx 5.6 Generic_105181-23 sun4u sparc SUNW,Ultra-60 > > I can run the following script without any problem : > > #!/usr/bin/perl > use strict; > use Expect; > my $exp = Expect->new; > $exp->raw_pty(1); > my $test = $exp->spawn('/usr/local/bin/ssh', -l => 'my_user', 'my_host') or > die "Cannot spawn command: $!\n"; > my @test1 = $exp->expect(5,'-re','password:'); > $exp->clear_accum(); > my @test2 = $exp->send("my_pass\r\n"); > my @test3 = $exp->expect(15,'-re','my_host'); > my @test4 = $exp->send("sh privilege\r\n"); > > The last command is exectuted successfuly. > > But if I try this : > > #!/usr/bin/perl > use strict; > use Expect; > use threads; > use threads::shared; > use Thread::Queue::Any; > > my $thread = threads->new(\&threadJob,); > $thread->join; > > sub threadJob{ > my $exp = Expect->new; > $exp->raw_pty(1); > my $test = $exp->spawn('/usr/local/bin/ssh', -l => 'my_user', 'my_host') > or die "Cannot spawn command: $!\n"; > my @test1 = $exp->expect(5,'-re','password:'); > $exp->clear_accum(); > my @test2 = $exp->send("my_pass\r\n"); > my @test3 = $exp->expect(15,'-re','my_host'); > my @test4 = $exp->send("sh privilege\r\n");# On envoie le mdp > } > > I actually get connected, but Expect don't interact anymore with ssh after > the logging. Instead, I can access the box, I telneted from STDIN ... > > Does anybody knows why I'm getting this strange behavior ? > > Btw, when I close the conection, the script finishes to run peacefully. > > -- > View this message in context: http://www.nabble.com/Trouble-with-Expect-working-with-Threads-tf4062209.html#a11541250 > Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |