Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#! /usr/bin/perl -w use strict; use constant MISSING => 'not specified'; my $first = shift or die "No first file given on command line.\n"; my $second = shift or die "No second file given on command line.\n"; open F, $first or die "Cannot open $first for input: $!\n"; my %f1 = contents( <F> ); close F; open F, $second or die "Cannot open $second for input: $!\n"; my %f2 = contents( <F> ); close F; for( sort {$f1{$a}->[0] <=> $f1{$b}->[0]} keys %f1 ) { if( !exists $f2{$_} ) { print "$first($f1{$_}->[0]) $_ not present in $second\n"; } elsif( defined $f1{$_}->[1] ) { if( !defined $f2{$_}->[1] ) { print "$first($f1{$_}->[0]) $_=$f1{$_}->[1] [$second($f2{$ +_}->[0]) not specified]\n"; } elsif( $f1{$_}->[1] ne $f2{$_}->[1] ) { print "$first($f1{$_}->[0]) $_=$f1{$_}->[1] [$second($f2{$ +_}->[0]) differs: $f2{$_}->[1]]\n"; } } } for( sort {$f2{$a}->[0] <=> $f2{$b}->[0]} keys %f2 ) { if( !exists $f1{$_} ) { print "$second($f2{$_}->[0]) $_ not present in $first\n"; } } sub contents { my %param; my %tag; my $line = 0; for( @_ ) { ++$line; /^\s*#\s*TAG:\s+(\S+)/ and $tag{$1} = $line; s/#.*$//; s/\s+$//; next unless $_; my( $key, $value ) = split( / /, $_, 2 ); $param{$key} = [$line, $value]; } for( keys %tag ) { $param{$_} = [$tag{$_}, undef] unless $param{$_} ; } %param; } =over 1 =head1 NAME diffsquid - compare squid configuration files =head1 SYNOPSIS B<diffsquid> filespec filespec =head1 DESCRIPTION Analyse two squid configuration files, and report parameters that are present in one file but not in the other, or have different values. Also attempt to identify valid parameter names in the comments and report on those as well (useful when new versions are released). =head1 OPTIONS =over 5 None. =head1 DETAILS By default, a squid configuration file "fresh out the box" contains no values, as sensible default values are chosen for everything. Fortunately most, if not all, parameters and their possible values appear in the comments. As an added bonus, they are easily greppable since those lines contain the string 'TAG:'. This script takes two filenames, which should be Squid configuration files, and isolates the TAG: comment lines to extract the parameter names, and extracts all the parameters with explicit values. It then compares the two sets of paramters and displays the differences: the parameters than exist in both files but have different settings, and parameters that exist in one file but not the other. =head1 EXAMPLES Here is an excerpt of the output when run with against a working 2.4.STABLE3 config and a freshly downloaded copy from 2.4.STABLE7. squid.conf-2.4.3(1051) connect_timeout=45 seconds [squid.conf-2.4.7(1 +200) not specified] squid.conf-2.4.3(1283) http_access=allow all [squid.conf-2.4.7(1462) +differs: deny all] squid.conf-2.4.3(1303) miss_access=allow all [squid.conf-2.4.7(1478) +not specified] These three lines indicate that two parameters are present in the firs +t file, but not in the second file. One parameter (http_access) is prese +nt in both files, but the value is different. The number in parentheses a +re line numbers. squid.conf-2.4.7(670) log_ip_on_direct not present in squid.conf-2.4. +3 squid.conf-2.4.7(707) referer_log not present in squid.conf-2.4.3 squid.conf-2.4.7(786) ftp_sanitycheck not present in squid.conf-2.4.3 These lines indicate new parameters in the second file that do not exist in the first file. This is probably an indication of new functio +nality that has been added to Squid in subsequent versions. =head1 BUGS The script is only as good as the comments it finds in the configurati +on file. =head1 COPYRIGHT Copyright (c) 2002 David Landgren. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR David "grinder" Landgren grinder on perlmonks (http://www.perlmonks.org/) eval {join chr(64) => qw[landgren bpinet.com]} =cut

In reply to diffsquid - find the differences in Squid configuration files by grinder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (5)
    As of 2014-09-24 00:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (243 votes), past polls