All pastes #419317 Raw Edit

Plasma Fox

public text v1 · immutable
·published 2007-04-01 07:03 UTC
rendered paste body
#!/usr/bin/perl -w
use strict;

my $file = shift || die $0.": parameters are $0 <file> <user> <ip>\n";
my $user = shift || die $0.": parameters are $0 <file> <user> <ip>\n";
my $ip   = shift || die $0.": parameters are $0 <file> <user> <ip>\n";

open(FILE, $file) or die $file.": $!\n";
my $filez;
my $read;
my @tmp; 

while ($read = <FILE>) {
	chomp($read);
	@tmp   = split(/\s/, $read);
	if ($tmp[1] =~ /$user/) {
		print "Found $user, changing $tmp[0] to $ip\n";	
		$filez .= $ip." #".$user."\n";
	}
	else { $filez .= $read."\n"; }
}

close(FILE);
open(WRITE, ">$file") or die $file.": failed to reopen for writing: $!\n";
print WRITE $filez;
close(WRITE);

print "Done\n";