My situation is this: My school used to have their student/faculty login system setup, so each user loged in with their full name "First Last". This 'full name' was actually a psydonym for the real UNIX username, which was u character, followed by 3-5 addititonal digits (ie u881).
We have since upgraded to a new server, and while doing so, decided to change the real unix usernames, from numbers, to a short version of the user name
Gabriel Rigg, u881 becomes Gabriel Rigg, grigg
I have two files in my posession:
1) a file containing old usernumbers, and full names:
-------------------------usrbynum.txt---------------------
----------------------------EOF----------------------------
and 2) a file containing new shortnames, and full names
-------------------------srnames.txt-----------------------
---------------------------EOF-----------------------------
There are a few issues to deal with. First, not everyone in short/full is in num/full, but I can deal with that later. However, here is my code:
To test whether or not the hashes of the different files were working, I commented most of the code out, and told it to to print to the screen. For example:
For both of the files and their while() statements used to extract data for the hashes, they printed the exact correct statements (even the newlines added up, so there were none because of the chomp). So, I know that, individually at least, these statements work.
The final few lines of the code is supposed to match shortnames to old usernumbers, via a matching long name (since its the shared constant between the files), and move all the files from the old usernumber/Directory to the short/Directory.
I added 'use strict; use warnings;', and got the following output:
However, without use strict and use warnings, the code execute with no errors, but no results.
Expected result was that a file ./testing/u881/Documents/test.txt would be moved to ./testing2/grigg/Documents/ . However, it does not get moved (obviously).
Any suggestions?
We have since upgraded to a new server, and while doing so, decided to change the real unix usernames, from numbers, to a short version of the user name
Gabriel Rigg, u881 becomes Gabriel Rigg, grigg
I have two files in my posession:
1) a file containing old usernumbers, and full names:
-------------------------usrbynum.txt---------------------
Code:
u880 name: Gabe Girard
u881 name: Gabriel Rigg
u882 name: Genna Bourget
... for about 263 of them
and 2) a file containing new shortnames, and full names
-------------------------srnames.txt-----------------------
Code:
fkasierderrick::1333:20::::Freya Kasier Derrick
grigg::1460:20::::Gabriel Rigg
omeara::1025:20::::Gary O'Meara
There are a few issues to deal with. First, not everyone in short/full is in num/full, but I can deal with that later. However, here is my code:
Code:
#!/usr/bin/perl
$oldserv = "./testing";
$newserv = "./testing2";
$usernumfile = "./usrbynum.txt";
$usershortfile = "./srnames.txt";
open USERNUMS, "< $usernumfile" or die "$!";
open SHORTNAMES, "< $usershortfile" or die "$!";# open file with user
# loop through all lines of shortnames
while (<SHORTNAMES>) {
my ($longname,$shortname) = (split /:/)[7,0];
# seperate by those ugly colen
$finishedusers{$longname} = $shortname;
chomp %finishedusers;
}
my %lookup; # Hash %lookup
while(<USERNUMS>) { # loop through file with user numbers
($uid) = /(u\d{3,5})/; # User ID find yes
($longname2) = /([A-Z]\w+)/;
chomp $longname2;
# Setup hash %lookup with keys "Long Name"=> "usernum"
$lookup{$longname2} = $uid;
}
while (($longname2, $uid) = each(%lookup)) {
next unless exists $finishedusers{$longname2};
system ("cp '$oldserv/$uid/Documents/*' '$newserv/$finishedusers{$longname2}/Documents/'");
print "Copying Files for $finishedusers{longname2}";
}
close USERNUMS;
close SHORTNAMES;
To test whether or not the hashes of the different files were working, I commented most of the code out, and told it to to print to the screen. For example:
Code:
while (<SHORTNAMES>) { # loop through all lines of shortnames
my ($longname,$shortname) = (split /:/)[7,0]; # seperate by those ugly colen
$finishedusers{$longname} = $shortname;
chomp %finishedusers;
}
while (($templong,$tempshort) = each(%finishedusers)) {
print "long: $templong \n short: $tempshort \n\n
}
The final few lines of the code is supposed to match shortnames to old usernumbers, via a matching long name (since its the shared constant between the files), and move all the files from the old usernumber/Directory to the short/Directory.
I added 'use strict; use warnings;', and got the following output:
Global symbol "$oldserv" requires explicit package name at doctrans2.pl line 6.
Global symbol "$newserv" requires explicit package name at doctrans2.pl line 7.
Global symbol "$usernumfile" requires explicit package name at doctrans2.pl line 8.
Global symbol "$usershortfile" requires explicit package name at doctrans2.pl line 9.
Global symbol "$usernumfile" requires explicit package name at doctrans2.pl line 11.
Global symbol "$usershortfile" requires explicit package name at doctrans2.pl line 12.
Global symbol "%finishedusers" requires explicit package name at doctrans2.pl line 15.
Global symbol "%finishedusers" requires explicit package name at doctrans2.pl line 16.
Global symbol "$uid" requires explicit package name at doctrans2.pl line 21.
Global symbol "$longname2" requires explicit package name at doctrans2.pl line 22.
Global symbol "$longname2" requires explicit package name at doctrans2.pl line 23.
Global symbol "$longname2" requires explicit package name at doctrans2.pl line 24.
Global symbol "$uid" requires explicit package name at doctrans2.pl line 24.
Global symbol "$longname2" requires explicit package name at doctrans2.pl line 27.
Global symbol "$uid" requires explicit package name at doctrans2.pl line 27.
Global symbol "%finishedusers" requires explicit package name at doctrans2.pl line 28.
Global symbol "$longname2" requires explicit package name at doctrans2.pl line 28.
Global symbol "$oldserv" requires explicit package name at doctrans2.pl line 29.
Global symbol "$uid" requires explicit package name at doctrans2.pl line 29.
Global symbol "$newserv" requires explicit package name at doctrans2.pl line 29.
Global symbol "%finishedusers" requires explicit package name at doctrans2.pl line 29.
Global symbol "$longname2" requires explicit package name at doctrans2.pl line 29.
Global symbol "%finishedusers" requires explicit package name at doctrans2.pl line 30.
Execution of doctrans2.pl aborted due to compilation errors.
However, without use strict and use warnings, the code execute with no errors, but no results.
Expected result was that a file ./testing/u881/Documents/test.txt would be moved to ./testing2/grigg/Documents/ . However, it does not get moved (obviously).
Any suggestions?