cryptonite1 has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, how do i get the complete string which has matched via regex when using Perl Expect.
#!/usr/bin/perl use Expect; use Getopt::Long; my $exp = Expect->spawn("/usr/bin/ssh $username\@$ip") or die "Cannot spawn ssh: $!\n";; /* removed the ssh handling code */ $exp->send("show backup status\n"); $result=$exp->expect( $timeout, ['-re',qr'Backup file location:',sub {my $exp = shift; $exp->print_log_file($backup_Complete); $i=0; } ], ['-re',qr'>'] );
Out put of the above command is :
How do we extract "location: /var/log/CPbackup/backups/x.x/x.x.x.x_01_1_Aug_2016_11_05.tgz" line from the output with perl expect ? Do note that i have tried to use $exp->match() but just displayes "Backup file location:" which is the regex=== local backup succeeded. Backup file location: /var/log/CPbackup/backups/x.x/x.x.x.x_01_1_Aug_2 +016_11_05.tgz Backup process finished in 00:48 seconds ===
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Expect : Get the complete matched string (updated)
by haukex (Archbishop) on Aug 02, 2016 at 06:37 UTC | |
by cryptonite1 (Initiate) on Aug 02, 2016 at 10:42 UTC | |
by haukex (Archbishop) on Aug 02, 2016 at 18:45 UTC | |
|
Re: Perl Expect : Get the complete matched string
by Anonymous Monk on Aug 02, 2016 at 13:51 UTC |