#! /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( ); close F; open F, $second or die "Cannot open $second for input: $!\n"; my %f2 = contents( ); 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 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(1200) 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 first file, but not in the second file. One parameter (http_access) is present in both files, but the value is different. The number in parentheses are 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 functionality that has been added to Squid in subsequent versions. =head1 BUGS The script is only as good as the comments it finds in the configuration 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