rdashokraj
asked on
Perl script help on adding variables in a loop
Hello Experts,
I need your help. I'm trying to write a Perl script which will get me the disk free space information in a solaris machine. But I'm stuck. Basically i would like to know the way for adding a particular variable cumulatively in a foreach loop. Below given is the portion of my code (full program attached in as file), where in a foreach loop, I'm matching some pattern from prtvtoc output of each disk and trying to extract a value in a variable $sect_cnt and then i want to do a cumulative addition of this variable, by which i can find the number of free sector available in the disk. Could you please help me in this?
foreach(@prtres)
{
if($_ =~ m/^[^\*]/)
{
($somethg, $slce, $tag, $flags, $first_sect, $sect_cnt, $Lst_sect, $mntdir)=split /\s+/, $_;
print "$dsknum[$i]:$_", "\n";
print $sect_cnt += $sect_cnt, "\n";
}
}
$i++;
}
Thanks,
Ashok
diskfree.txt
I need your help. I'm trying to write a Perl script which will get me the disk free space information in a solaris machine. But I'm stuck. Basically i would like to know the way for adding a particular variable cumulatively in a foreach loop. Below given is the portion of my code (full program attached in as file), where in a foreach loop, I'm matching some pattern from prtvtoc output of each disk and trying to extract a value in a variable $sect_cnt and then i want to do a cumulative addition of this variable, by which i can find the number of free sector available in the disk. Could you please help me in this?
foreach(@prtres)
{
if($_ =~ m/^[^\*]/)
{
($somethg, $slce, $tag, $flags, $first_sect, $sect_cnt, $Lst_sect, $mntdir)=split /\s+/, $_;
print "$dsknum[$i]:$_", "\n";
print $sect_cnt += $sect_cnt, "\n";
}
}
$i++;
}
Thanks,
Ashok
diskfree.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm not sure if the info by prtvtoc is the same, but you might want to look at these modules:
Filesys::Df:
http://search.cpan.org/~iguthrie/Filesys-Df-0.92/Df.pm
Filesys::DiskSpace:
http://search.cpan.org/~ftassin/Filesys-DiskSpace-0.05/lib/Filesys/DiskSpace.pm
Filesys::Df:
http://search.cpan.org/~iguthrie/Filesys-Df-0.92/Df.pm
Filesys::DiskSpace:
http://search.cpan.org/~ftassin/Filesys-DiskSpace-0.05/lib/Filesys/DiskSpace.pm
ASKER
Adam, I could use your addition logic and make it working for me. I need one more help.
Is it possible to extract the value of $sect_cnt variable, when $slce is 2 (you can see this in second column under Slice heading) and then subtract this value from $sect_cnt_cum.
Basically, I'm trying to get the value of "Total number of Sectors availabe" - "Total number of sectors used"
Is it possible to extract the value of $sect_cnt variable, when $slce is 2 (you can see this in second column under Slice heading) and then subtract this value from $sect_cnt_cum.
Basically, I'm trying to get the value of "Total number of Sectors availabe" - "Total number of sectors used"
ASKER
Sorry forgot to attached the modified code
dskfree.txt
dskfree.txt
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adam, Thanks a lot for your quick response!!!! I got the result i want. This is the first time in my life, i have written a script (ofcourse with your help :-) which i consider really worth it. Thanks again!!
ASKER