Hello,
I need help with a perl script that will process a text file and match virtual server name to profile(s). the rest will be ignored.
Virtual server name follows the word "virtual" in the begging of the line.
There could be multiple profiles assigned to one virtual server.
For example, a file that look like this:
---------------------------
monitor Test-ICMP4 {
defaults from icmp
dest 10.2.34.81
transparent
virtual VS-Bridge1 {
snatpool SNAT-IP-Banorte
pool Bridge1-pool
destination 10.2.33.102:vpad
ip protocol tcp
rules iRule-Bridge1-Logging
profiles {
Bridge1_SSL_Profile {
serverside
}
fastl4 {}
}
vlans {
External-VLAN
PlanetSwitch-VLAN
} enable
}
virtual VS-Bridge_test {
destination 10.2.33.59:https
ip protocol tcp
rules {
iRule-testLogging
}
profiles {
SECURE2_SSL_Profile {
clientside
}
http {}
stream {}
tcp {}
}
vlans {
External-VLAN
Internal-VLAN
} enable
--------------------------------------
the output should look like this:
Virtual Server Profiles
VS-Bridge1 Bridge1_SSL_Profile, fastl4
VS-Bridge_test SECURE2_SSL_Profile, http, stream, tcp
I appreciate your help.
Thanks:wall:
$ cat virt2.awk
(STACK[DEP]=="profiles") && ($NF != "}") { X=X "," $1 }
$NF == "{" {
INROW=0;
STACK[++DEP]=$1
if(NF>2) PARAM[$1]=$2
next
}
{
for(N=1; N<=NF; N++)
if($N == "}")
{
DEP--
INROW++
}
if((INROW == 2)&&(DEP==2))
{
print PARAM["virtual"], substr(X,2);
X=""
}
}
$ awk -f virt2.awk data
VS-Bridge1 Bridge1_SSL_Profile,fastl4
VS-Bridge_test SECURE2_SSL_Profile,http,stream,tcp
$
#!/usr/bin/perl
use strict;
my $prof;
$/="\n\n";
print "Virtual Server Profiles \n";
while (<DATA>) {
if (/virtual\s+(.*?)\s*\{(.*?)profiles\s*\{(.*?)\s*\{(.*?)\}(.*)\}(.*)vlans/sg) {
my $ser=$1;
$prof=$3;
chomp $prof;
my $str=$5;
$prof=~s/^\s+//g; $prof=~s/\s+$//g;
$str=~s/^\s+//g; $str=~s/\s+$//g;
$str=~s/[\{\}]//g; $str=~s/\n/,/g; $str=~s/,\s+/,/g;
print $ser,"\t\t",$prof,",",$str,"\n";
}
}
__DATA__
monitor Test-ICMP4 {
defaults from icmp
dest 10.2.34.81
transparent
virtual VS-Bridge1 {
snatpool SNAT-IP-Banorte
pool Bridge1-pool
destination 10.2.33.102:vpad
ip protocol tcp
rules iRule-Bridge1-Logging
profiles {
Bridge1_SSL_Profile {
serverside
}
fastl4 {}
}
vlans {
External-VLAN
PlanetSwitch-VLAN
} enable
}
virtual VS-Bridge_test {
destination 10.2.33.59:https
ip protocol tcp
rules {
iRule-testLogging
}
profiles {
SECURE2_SSL_Profile {
clientside
}
http {}
stream {}
tcp {}
}
vlans {
External-VLAN
Internal-VLAN
} enable
OR
#!/usr/bin/perl
use strict;
my $prof;
$/="virtual";
print "Virtual Server Profiles \n";
while (<DATA>) {
if (/(.*?)\s*\{(.*?)profiles\s*\{(.*?)\s*\{(.*?)\}(.*)\}(.*)vlans/sg) {
my $ser=$1;
$prof=$3;
chomp $prof;
my $str=$5;
$prof=~s/^\s+//g; $prof=~s/\s+$//g;
$str=~s/^\s+//g; $str=~s/\s+$//g;
$str=~s/[\{\}]//g; $str=~s/\n/,/g; $str=~s/,\s+/,/g;
print $ser,"\t\t",$prof,",",$str,"\n";
}
}