#!/usr/bin/perl use Expect; my $access_protocol = 'ssh'; my $host = 'myhost.mycompany.com'; my $timeout = 15; my $username = 'svc_network_readonly'; my $password = 'sc00byd00byD00'; $Expect::Log_Stdout = 0; my @commands = ("show virtual-chassis", "show version", "show arp no-r +esolve", "show ethernet-switching table", "exit"); my $exp = Expect->spawn("$access_protocol -l $username $host") or die +"Can't connect to $host: $!\n"; my $match="^$username\@$host. "; $exp->expect ($timeout, ['^\-\-\-.more', sub { $x = $exp->before(); print "$x"; $exp->send(" "); exp_continue; }], [ qr /$username\@$host\'s password: /, sub { $exp->send("$password\n"); exp_continue; }], [ $match, sub { my $cmd=shift(@commands); $x = $exp->before(); print "$x"; $exp->send("$cmd\n"); exp_continue; }], ['timeout', sub { print "A timeout has occurred - no match found\n"; }], '-re', '] $');
In reply to Re: Screen Scraping from Juniper Switch using Expect.pm - Multiple Commands
by mrdavis94
in thread Screen Scraping from Juniper Switch using Expect.pm - Multiple Commands
by julio-johnson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |