#!/usr/bin/perl

use File::Find;

print "#ARGV=$#ARGV\n";
if ($#ARGV != 1) { print "need two parameters: login last3digitsOfSID\n"; exit(1); }
$login=$ARGV[0];
$last3digits=$ARGV[1];
if (!$login) { print "login can not be null"; exit(1); }
if ($last3digits !~ /\d{3}/) { print "2nd parameter needs to 3 digits\n"; exit(1); }
print "LOGIN=$login last3d=$last3digits\n";

$sedcmd= "sed -e \'s/LOGIN/$login/g\' -e \'s/<last3DigitsSID>/$last3digits/g '";
print "sedcmd=$sedcmd\n";

#opendir(DIR, "apache");
#@FILES=readdir(DIR);
#foreach $file (@FILES) {
#   print "file=$file\n";
#}

$dir="apache";
find(\&edits, $dir);
sub edits() {
   $file=$_;
   print "file=$file\n";
   system("$sedcmd $file > temp; mv temp $file; chmod 755 $file");
}
