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]#
In reply to Re^2: IP address validation when IP is picked dynamically
by rahulruns
in thread IP address validation when IP is picked dynamically
by rahulruns
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |