#/usr/bin/perl
$file_name = "etc/passwd"; #Password file
$new_file_name = "passwd.new"; #Updated file
$id = 10000; #initial id
#####cpf.pl##################################################
# This program opens the etc/passwd file and copies it to
# passwd.new in this directory untill it finds the first
# student (2 to 4 letters followed by 4 digits). When
# encountered the user id is changed to 10000. This new id
# is given by the variable $id in which is incremented for
# use when this code is implimented into the bigger pogram
# that will make all the changes to include the group file
# also.
#
# INPUT: none
# OUTPUT: new file called passwd.new in the calling dir.
# DEPENDENCIES: none
# DATE: March 26, 2001
# AUTHOR: William Martin
#############################################################
#####open files##############################################
open(FILE, $file_name) or die "Error opening $file_name: $!\n";
print"\n File $file_name has been opened\n";
open(NEW_FILE, ">$new_file_name") or
die "Error opening $new_file_name: $!\n";
print" File $new_file_name has been created\n\n";
#####read file, write to new and make changes to first student
#####found with a group id < 10000###########################
while (){
if (?^[a-z]{2,4}[0-9]{4}?){
@line = split(/:/,$_);
print" Found student $line[4]\n";
$student = $line[0];
$home_dir = $line[5];# need this to change file ownerships
print NEW_FILE "$student:$line[1]:$id:$id:$line[4]:$line[5]:$line[6]";
print" Changed user id $line[2] to $id\n";
next;
};
print NEW_FILE;
}
#####close files##############################################
close(FILE);
close(NEW_FILE);
print"\n Files have been closed!\n";