My script runs without error but is not making changes to the files that it finds.
And, there are two lines in the master file and it appears the loop is not getting to the second line.
And, it is not renaming any files to .bak
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my $opsys = $^O;
my $hostname = qx |uname -a| or die("Can't get info for hostname: $!\n
+");
my @uname = split (/\s/, $hostname);
my $searchdir = '/dir/etc-test';
print ">>> Operating System: $opsys" . "\n";
print ">>> Hostname: $uname[1]\n";
open (my $FH, '<', 'ipmastr') or die "Could not open 'ipmaster' : $!";
+
while (<$FH>){
chomp;
my ($ipold, $ipnew, $nmold, $nmnew, $dgold, $dgnew, $ns1old, $ns1n
+ew, $ns2old, $ns2new, $ip6old, $ip6new) = split (/\t/);
$^I = '.bak';
find(\&wanted, $searchdir);
sub wanted {
my $filename = $File::Find::name;
print "$ipold - Filename is: $filename\n";
return unless -f $filename;
open (FR, '<', '$filename') or print "Could not read $filename
+\n" && return;
my @lines = <FR>;
close (FR);
open (FW, '>', '$filename') or print "Could not open for write
+ $filename\n" && return;
for ( @lines ) {
s/$ipold/$ipnew/g;
print FW $_;
}
close FW;
}
}
close $FH;
MY OUTPUT
user@host:erl: ./update-text.pl
>>> Operating System: linux
>>> Hostname: host.com
10.41.37.99 - Filename is: /dir/etc-test
10.41.37.99 - Filename is: /dir/etc-test/resolv.conf
10.41.37.99 - Filename is: /dir/etc-test/sysconfig
10.41.37.99 - Filename is: /dir/etc-test/sysconfig/network
10.41.37.99 - Filename is: /dir/etc-test/sysconfig/network-scripts
10.41.37.99 - Filename is: /dir/etc-test/sysconfig/network-scripts/ifcfg-eth0
10.41.37.99 - Filename is: /dir/etc-test/sysconfig/network-scripts/ifcfg-eth1
10.41.37.99 - Filename is: /dir/etc-test/sysconfig/network-scripts/ifcfg-lo
10.41.37.99 - Filename is: /dir/etc-test
10.41.37.99 - Filename is: /dir/etc-test/resolv.conf
10.41.37.99 - Filename is: /dir/etc-test/sysconfig
10.41.37.99 - Filename is: /dir/etc-test/sysconfig/network
10.41.37.99 - Filename is: /dir/etc-test/sysconfig/network-scripts
10.41.37.99 - Filename is: /dir/etc-test/sysconfig/network-scripts/ifcfg-eth0
10.41.37.99 - Filename is: /dir/etc-test/sysconfig/network-scripts/ifcfg-eth1
10.41.37.99 - Filename is: /dir/etc-test/sysconfig/network-scripts/ifcfg-lo
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.