02-09-2015 06:01 AM
Hi everybody,
I am writing a perl embedded script in order to get information about pseudowires.
I need to get the output of this ksh command: l2vpn_show -d 0x1 | grep -E "(Group.*XC)"
The problem is that when I execute this command by the shell CLI it works. If I try to make it run by a perl program it faults, probably because the | (pipe) char is not execute.
The line I write is:
my $cli_output = `l2vpn_show -d 0x1 | grep -E "(Group.*XC)"`;
It faults even this command:
my $cli_output = `l2vpn_show -d 0x1 | grep Group`;
Any hint to help me?
Regards
Raffaele Tostini
02-10-2015 11:43 AM
Hi Raffaele,
Perl itself is not good with pipes. Parce the $cli_output inside your script for a required matching pattern.
Regards,
Alex.
02-11-2015 01:40 AM
Which language can you suggest me as a best way to use ?
Thanks
Raffaele
02-11-2015 07:29 AM
you can use perl and ksh scripting and officially supported EEM (with TCL). My idea was not to change to another language but to show that in perl itself it is not straight forward to pipe commands from shell and if there is a need to get specific lines from $cli_output then you parce this variable by using perl like
my $cli = `l2vpn_show -d 0x1` ; my @lines = split /\n/, $cli; foreach my $line( @lines ) { if ($line =~ /Group.*XC/) { print $line . "\n"; } }
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide