in reply to Re: IP address validation when IP is picked dynamically
in thread IP address validation when IP is picked dynamically
Guys got this resolved finally. Spaces were a problem with IP address catch. Removed spaces from both ends (left and right)
#!/usr/bin/perl use strict; use warnings; use Acme::Tools; 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"; $parameter_value =~ s/^\s+|\s+$//g; if ( lc "$key" eq lc "ipaddr" ) { if (is_ipv4($parameter_value)) { print "Yes"; } } } } #Outer Foreach Result [root@localhost bond]# perl ifcfgbondverification.pl Enter the absolute directory location for ifcfg files /root/office/ifcfgverification/bond YesYesYesYesYesYesYes[root@localhost bond]#
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: IP address validation when IP is picked dynamically
by fishmonger (Chaplain) on May 01, 2015 at 16:49 UTC | |
by rahulruns (Scribe) on May 26, 2015 at 04:14 UTC |