From: Andrew C. <an...@xt...> - 2003-10-10 04:09:12
|
I hope this comes out O.K. My crappy mailler won't let me set the word wrap. On Wed, 2003-10-08 at 17:30, Austin Schutz wrote: > Yeah, that's what you do. You don't need to do interact to accomplish > this. Also, you can use the '-i' flag to expect() to wait for input from both > the device and the user. > Well, that's how I would do it anyway. > > > Austin Following that advice and shamelessly stealing from various examples, I've basically got that working. The guts are: ## Router interface etc configured. ## Logon to the device. $net_telnet->print("telnet $ipaddress /vrf $VRF"); ## Create a handle to STDIN my $stdin = Expect->exp_init( \*STDIN ); $stdin->stty(qw(raw -echo)); $stdin->log_stdout(0); ## Create a handle for the telnet session my $device = Expect->exp_init( \*$net_telnet ); $device->log_stdout(1); $device->log_file($expect_log); $stdin->set_group($device); ## If we see the router prompt we're not on the ## remote device anymore. Exit the expect loop. expect( undef, '-i', [$device], [qr'ROUTER#$'], '-i', [$stdin], [ qr'\n', sub { exp_continue; } ], ); ## Reset teminal or carriage returns get screwed up. $stdin->stty(qw(sane)); print "\nCleaning up config.\n"; bless $net_telnet, 'Net::Telnet'; ##Remove interface and exit. This all seems to be working great. The main problem I had was being able to see what I was typing without the input line being echoed after I pressed enter. After trying a huge combination of terminal settings I read about $exp->set_group and that fixed everything. The beauty of this setup is by adding more regexs you could parse/filter the input. For anyone who's wondering, I always use a Net::Telnet object instead of a raw IO socket on TCP 23 because I got caught out a while back by hosts expecting telnet options you can't do with raw IO. Having struggled through this I'm "interested" now, so I'd appreciate any comments or suggestions on how to do this better. Thanks for everyones help. Cheers, Andrew Anyone who isn't confused really doesn't understand the situation. -Edward R. Murrow. 1908-1965. |