-
-
Save grifferz/1c478ea5eb789b2a1d1a3e49d2a9345c to your computer and use it in GitHub Desktop.
compare one host's file+permissions list to another's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
# NULL-delimited fields. | |
$/ = "\0"; | |
my %perms; | |
open my $gfh, "< good-perms" or die "open"; | |
while (<$gfh>) { | |
if ($_ =~ m{(.*)\s(\d+)\0$}) { | |
$perms{$1} = $2; | |
} else { | |
die "weird entry found in good-perms: $_"; | |
} | |
} | |
close($gfh); | |
open my $sfh, "< suspect-perms" or die "open"; | |
while(<$sfh>) { | |
if ($_ =~ m{(.*)\s(\d+)\0$}) { | |
my $path = $1; | |
my $permissions = $2; | |
check_permissions($path, $permissions); | |
} else { | |
die "weird entry found in suspect-perms: $_"; | |
} | |
} | |
close($sfh); | |
exit 0; | |
sub check_permissions { | |
my ($path, $permissions) = @_; | |
if (not exists $perms{$path}) { | |
printf "Good host doesn't have: <%s> [%s]\n", $path, $permissions; | |
} elsif ($permissions eq $perms{$path}) { | |
# Permissions were the same so don't say anything. | |
} else { | |
printf "chmod %s %s # Mine was [%s]\n", | |
$perms{$path}, $path, $permissions; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment