Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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 ( eval {join chr(64) => qw[landgren]} =cut

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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2021-09-18 17:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found