Extracting_info_from_bigip_conf

Problem this snippet solves:

A simple perl script that allows you to locate a block contain an element withing bigip.conf

How to use this snippet:

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)

Code :

# Script Source

#!/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"; 
 } 

# SAMPLE

[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 
 $ ./test.pl h 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]" 
 } 
 --- 

# NOTE: It's not well tested, use it on your own risk and on dev machine first.
Published Mar 17, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment