Last active
February 25, 2016 04:10
-
-
Save masasuzu/e405b917711be9f7dad0 to your computer and use it in GitHub Desktop.
要はshadowのパスワード部分を埋めれば良いんでしょ?
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/perl | |
use strict; | |
use warnings; | |
use 5.14.2; | |
# perl shadow_ohikkoshi.pl OLD_SERVER_SHADOW NEW_SERVER_SHADOW OUTPUT_SHADOW | |
my ($origin_shadow, $new_shadow, $output_shadow) = @ARGV; | |
open my $origin, '<', $origin_shadow or die $!; | |
open my $new, '<', $new_shadow or die $!; | |
open my $out, '>', $output_shadow or die $!; | |
my $data = +{}; | |
while (my $line = <$origin>) { | |
chomp $line; | |
next unless $line; | |
my ($user, $password) = split(/:/, $line); | |
next if $user =~ /mf|root/; | |
$data->{$user} = $password; | |
} | |
close $origin; | |
while (my $line = <$new>) { | |
chomp $line; | |
next unless $line; | |
my ($user) = split(/:/, $line); | |
if (exists $data->{$user}) { | |
say $out ($line =~ s/!/$data->{$user}/r); | |
} | |
else { | |
say $out $line; | |
} | |
} | |
close $new; | |
close $out; | |
chmod 0640, $output_shadow; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment