#!/usr/perl/bin #=============================================================# # # # #==============================================================# use strict; use File::Find; use Sys::Hostname; my $fileupdate; my $old_hostname = hostname(); #current hostname my ($orig,$concat,$new_hostname,$answer); my @lines = " "; my $new_hostname = ""; ## Create new hostname based on physical address ### $new_hostname = shift; if ($new_hostname eq "" ) { open(I,'ipconfig /all |'); while() { next unless /Physical Address/; /:/; chomp; tr/-//d; $new_hostname = "css" .(lc substr($_, -6,5)) ; last; } print "Current host name of machine is :$old_hostname \n"; print "The new host name is going to be: $new_hostname\n"; } if ( $old_hostname ne $new_hostname ) { &personalization; } else { print "System already personlized\n"; } #--------------------------------------------------------------------------------------------- sub personalization { open(FH,") { print "line $line\n"; if( $line =~ /(.*)$old_hostname(.*)/i ) # any files that contain the substring of the old hostname { print "file that match $line\n"; $orig = $line; $concat = $line; $concat =~ s/(.*)$old_hostname(.*)/$1$new_hostname$2/gi; #CALL UPDATE SUBROUTINE &modified_file($concat); rename($orig, $concat) || print "error can't rename $orig to $concat: $!"; } else { &modified_file($orig ); } } } #--------------------------------------------------------------------------------------------- sub modified_file { $fileupdate = shift; open (IN,"<$fileupdate"); @lines = ; close IN; my $change_count = 0; @lines = map { $change_count++ if s/$old_hostname/$new_hostname/sgi; $_ } @lines; next unless $change_count; open (OUT,">$fileupdate") || "can't open $fileupdate for writing :$! "; print OUT @lines; close OUT;