Forum Discussion
don_23889
Nimbostratus
Dec 28, 2009grep'ng for 'string' in bigip.conf
grep'ng for 'string' and returning entire block of object definitions from bigip.conf for each instance of 'string', starting with 'virtual' and ending with '}'
config less bigip.conf |grep -B5 -A5 string |more
This is cumbersome since you have to guess for -B(x) and -A(x)
So, as an example, I want to return all object definitions with iRule 'http-xff'. Basically, all lines between [virtual] and [}]
This example is syntactically incorrect, and only for illustrating what I am trying to achieve....ie...pseudo-code.
less bigip.conf |grep BEGIN[virtual] END[}] http-xff |more
virtual vip1.80 {
pool vip1.80
destination aaa.bbb.ccc.ddd:http
ip protocol tcp
rules SNAT2VIP
profiles
http-xff
tcp-lan-optimized
serverside
tcp-wan-optimized
clientside
persist source_addr_30min
}
virtual vip-2.80 {
pool vip-2.80
destination mmm.nnn.ooo.ppp:http
ip protocol tcp
rules SNAT2VIP
profiles
http-xff
tcp-lan-optimized
serverside
tcp-wan-optimized
clientside
persist source_addr_30min
}
What would really be sweet, would be to grep for a given 'string', and return entire block for 'any' object definition...where the preceding line and following line are are both blank. This would return all object definitions for a given string...virtual, pool, monitor...etc.
- The_Bhattman
Nimbostratus
Hi Don, - hwidjaja_37598
Altostratus
Try using perl, cut and paste this code to a file (eg. /tmp/mygrep.pl) and make sure the executable bit is set (eg. chmod a+x /tmp/mygrep.pl)!/usr/bin/perl use strict; my ($File, $Pattern) = @ARGV; my $buf; open (fh, $File) || die "Cant open $File"; { local $/; $buf=; } close (fh); while ($buf =~ /([^\n]*\{[^\{]*$Pattern[^\}]*\})/sg){ print "$1\n---\n"; }
[root@bigip:Active] config /tmp/mygrep.pl /config/bigip.conf http-xff virtual vip1.80 { pool vip1.80 destination aaa.bbb.ccc.ddd:http ip protocol tcp rules SNAT2VIP profiles http-xff tcp-lan-optimized serverside tcp-wan-optimized clientside persist source_addr_30min } --- virtual vip-2.80 { pool vip-2.80 destination mmm.nnn.ooo.ppp:http ip protocol tcp rules SNAT2VIP profiles http-xff tcp-lan-optimized serverside tcp-wan-optimized clientside persist source_addr_30min } --- [root@bigip:Active] config /tmp/mygrep.pl /config/bigip.conf password user root { password crypt "[cut]" } --- user admin { password crypt "[cut]" description "Admin User" group [cut] home "[cut]" shell "[cut]" role administrator in all } --- user f5emsvr { password crypt "[cut]" description "F5 EM Service Account" id [cut] group [cut] home "[cut]" shell "[cut]" role guest in all } --- configsync { password crypt "[cut]" } ---
- Jessed12345
Employee
A slight improvement: - Don_Munyak
Nimbostratus
Thanks everyone ... much appreciated. I will spend some time testing reults on our dev box. - Don_Munyak
Nimbostratus
Posted By hwidjaja on 12/28/2009 10:26 AM
!/usr/bin/perl use strict; my ($File, $Pattern) = @ARGV; my $buf; open (fh, $File) || die "Cant open $File"; { local $/; $buf=; } close (fh); while ($buf =~ /([^\n]*\{[^\{]*$Pattern[^\}]*\})/sg){ print "$1\n---\n"; }
- hwidjaja_37598
Altostratus
$buf = ; is correct. - Don_Munyak
Nimbostratus
With respect to awk '/^virtual/,/^}$/' /config/bigip.conf - The_Bhattman
Nimbostratus
Hi Don,/tmp/mygrep.pl /config/bigip.conf SNAT2VIP
- hwidjaja_37598
Altostratus
hmm try this ...awk 'BEGIN {RS="}";FS=RS} /rules SNAT2VIP/ {print $1"}";} ' /config/bigip.conf
- Don_Munyak
Nimbostratus
SWEAT ... exactly what I was hoping for.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects