in reply to IP address validation when IP is picked dynamically
Yeah you missed the chomp() in while loop as mentioned by toolic.More over did little bit changes in the script.
#!/usr/bin/perl use strict; use warnings; use Data::Validate::IP qw(is_ipv4); print "Enter the absolute directory location for ifcfg files\n"; my $directory = <>; chomp($directory); opendir(DIR, $directory) or die "couldn't open $directory: $!\n"; my @ifcfg_files = grep { /^ifcfg-bond/ } readdir(DIR); closedir DIR; foreach (@ifcfg_files) { my %hash = (); my $file = "$_"; open (my $fh, "<", $file) or die "Can't open the file $file: "; while (my $line =<$fh>) { chomp($line); next if $. <= 2; # Added '=' my($key, $parameter_value) = split("=", $line); next if $key eq "BONDING_OPTS"; if (is_ipv4($parameter_value)) { print "Success -> $key:$parameter_value\n"; } else{ print "Failed -> $key:$parameter_value\n" } } } #Outer Foreach
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: IP address validation when IP is picked dynamically
by rahulruns (Scribe) on May 01, 2015 at 13:49 UTC | |
by toolic (Bishop) on May 01, 2015 at 14:00 UTC | |
by Laurent_R (Canon) on May 01, 2015 at 14:10 UTC |