#!/usr/perl/bin #=============================================================# # #This script traverse directory updating files and directories names # #==============================================================# use strict; use File::Find; use Win32::AdminMisc; use Sys::Hostname; my $old_hostname = hostname(); #current hostname my ($new,$orig,$changed,$concat,$new_hostname, $result,$f,$file, $str,$ln,$line, @files,$linr ); my @lines = " "; my @files; my @fixedDrives = Win32::AdminMisc::GetDrives(DRIVE_FIXED); ## Create new hostname based on physical address ### print "Current host name of machine is :$old_hostname \n"; $new_hostname = "csscs_ref"; print "The new host name is going to be: $new_hostname\n"; #-------------------------------------------------------------------------------------------------------------------------- print "Looking for files to rename \n"; finddepth (\&rename_file_dir , @fixedDrives ); finddepth (\&modified_file , @fixedDrives ); #---------------------------------------------------------------------------------------------------------------------------- sub rename_file_dir { if( /(.*)$old_hostname(.*)/i )# any files or directories { $orig = $File::Find::name ; print "rename_file_dir : $orig\n"; $concat = $File::Find::dir . "\/$1$new_hostname$2"; rename($orig, $concat) || print "error can't rename $orig to $concat: $!" } } # end of sub update_file #------------------------------------------------------------------------------------------------------------------------- sub modified_file { if (-f "$File::Find::name" and (! -B "$File::Find::name")){ print "modified_file sub : $File::Find::name\n"; open (IN,"$File::Find::name"); @lines = ; close IN; @lines = map { s/\b$old_hostname\b/$new_hostname/sgi; $_ } @lines; open (OUT,">$File::Find::name") || "can't open $File::Find::name for writing :$! "; print OUT @lines; } }