1837737 Members
3901 Online
110118 Solutions
New Discussion

Re: disk usage script

 
SOLVED
Go to solution
himacs
Super Advisor

disk usage script

Hi Admins,

I need a script which has to give following outputs..
1.number of VG presence with VG name
2.Total+used+free space per VG

please help on this

Regards
himacs
13 REPLIES 13
Mel Burslan
Honored Contributor

Re: disk usage script

# of VGs

strings /etc/lvmtab | grep "^/dev" | /grep -v "/dev/dsk"| wc -l

# usage

for vg in `strings /etc/lvmtab | grep -v "/dev/dsk"`
do
pesize=`vgdisplay $vg | grep "^PE Size"|awk {'print $4'}
usedpe=`vgdisplay $vg | grep "^Alloc PE"|awk {'print $3'}
(( usedmb=${usedpe}*${pezise} ))
freepe=``vgdisplay $vg | grep "^Free PE"|awk {'print $3'}
(( freemb=${freepe}*${pezise} ))

echo "${vg} has ${usedmb} MBs used and ${freemb} MBs free space"
done

hope it helps
________________________________
UNIX because I majored in cryptology...
himacs
Super Advisor

Re: disk usage script

Hi Admins,
Actually i have a script but it throws error while executing..

#This pgm will display Total, Used and Free size(in MB) of all vgs in a system

system("vgdisplay |grep -e 'Name' -e 'Total PE' -e'Alloc' -e'Free'|cut -b 29- >/tmp/bdf.out");
print("Name\t Total MB\tUsed MB\tAvailable MB\n");

open (BDF,"/tmp/bdf.out");
$line=;
chop $line;
while ($line ne "")
{
if ($line =~/vg/){
$count=1;
}
while($count < 5){
if($count > 1){
$line=$line*$pe_size;
}
else {
&get_pe_size;
}
print("$line \t");
$line=;
chop $line;
++$count;
}
print("\n");
}

sub get_pe_size {
$vgname="vgdisplay $line";
open (WOUT,"$vgname |grep Mbyte|cut -b 28-30|");
$pe_size=;
chop $pe_size;
}

eror is - free[3]: Syntax error at line 3 : `(' is not expected.
Plz let me know what causes this error..


regards
himacs
James R. Ferguson
Acclaimed Contributor
Solution

Re: disk usage script

Hi Himacs:

> Actually i have a script but it throws error while executing..

Then _SAY_SO_.

Aside from your script being terribly un-Perlish it _IS_ a perl script and thus needs to be indentified as such.

Every good script needs to declare the interpreter it wants to use in a "she-bang" line. Failure to do so means that a shell is assumed.

Add this as the first line of your script:

#!/usr/bin/perl

...or if that fails:

#!/usr/bin/env perl

Regards!

...JRF...
himacs
Super Advisor

Re: disk usage script

Hi JRF,

Thanx for the guidance..its worked
i added #!/usr/bin/perl as interpreter.

The same script i got from itrc after posting this thread..

anyway thanx once again..

Hi Mel ,
I executed the script suggested by u,but some errors..
./freetest[11]: /dev/vg00: Execute permission denied.
./freetest[12]: usedmb=* : Syntax error

anyhow i found ineterest ininformation in scripting with ur help.. thanx

regards
himacs
Mel Burslan
Honored Contributor

Re: disk usage script

my script was untested and as expected from any caffeine-less morning, was riddled with typographic errors.

here is a working copy:

for vg in `strings /etc/lvmtab | grep -v "^/dev/dsk" | grep "^/dev"`
do
pesize=`vgdisplay $vg | grep "^PE Size"|awk {'print $4'}`
usedpe=`vgdisplay $vg | grep "^Alloc PE"|awk {'print $3'}`
usedmb=`echo "${usedpe}*${pesize}" | bc`
freepe=`vgdisplay $vg | grep "^Free PE"|awk {'print $3'}`
freemb=`echo "${freepe}*${pesize}" | bc`

echo "${vg} has ${usedmb} MBs used and ${freemb} MBs free space"
done

HTH
________________________________
UNIX because I majored in cryptology...
himacs
Super Advisor

Re: disk usage script

Hi JRF,

One more thing..

I want to display total PVs present in VG also..

how can we edit the same script to achieve thhat..


regards
himacs
himacs
Super Advisor

Re: disk usage script

Hi Plz tell me why ~ and ^ used in script..


regards
himacs
Mel Burslan
Honored Contributor

Re: disk usage script

pvcount=`vgdisplay -v $vg| grep "PV Name" | grep -v "Alternate Link" | wc -l`

in my script you can put this line before the echo statement and on the echo line, incorporate the pvcount into printable variables as you desire.
________________________________
UNIX because I majored in cryptology...
Mel Burslan
Honored Contributor

Re: disk usage script

with my limited perl knowledge, ~ is used to suppress blan lines in the output. I can not see any ^ (carat) characters in the perl script but in regular expressions, ^ means the beginning of the line.
________________________________
UNIX because I majored in cryptology...
himacs
Super Advisor

Re: disk usage script

Hi Mel,

Thanx for the info..

If i want to direct the output where should i add >/tmp/disk.out

I tried with adding in the end of echo line but ended up with directing ony VG00 info..

regards
himacs
Mel Burslan
Honored Contributor

Re: disk usage script

if you want to redirect at the end of echo, you need to use >> as this one will get executed as many times as the number of vg's you have.

to use > (single redirect) do it after the word "done", for example:

...
echo "blah-blah..."
done > /tmp/myreport.txt

HTH
________________________________
UNIX because I majored in cryptology...
James R. Ferguson
Acclaimed Contributor

Re: disk usage script

Hi (again) Himacs:

> One more thing..I want to display total PVs present in VG also.

One way is to add this section of Perl code to the end of what you have:

my ( $fh, $vgname, $nbrpvs );
open( my $fh, '-|', '/sbin/vgdisplay' ) or die $!;
while (<$fh>) {
$vgname = $1 if m{^VG Name\s+(.+)};
$nbrpvs = $1 if m{^Act PV\s+(.+)};
if ( defined $vgname and defined $nbrpvs ) {
printf "%-12s = %02d PVs\n", $vgname, $nbrpvs;
undef $vgname;
}
}

I would rewrite the whole script in this fashion...using an piped open() to read the output of 'vgdisplay'. The caret (^) means match at the beginning of a line. The '\s+' means one or more whitespaces (tabs, spaces, etc.). The '.+' means one or more of any character and by enclosing it in parentheses we capture whatever is seen in the '$1' variable.

As you can see, the whole script could be re-factored into a loop driven by the above.

Regards!

...JRF...
d miller_2
Advisor

Re: disk usage script

Hello,

If you're familiar with perl, there's an HPUX::LVM perl module on CPAN that automatically parses vgdisplay/lvdisplay/pvdisplay into a perl hash. Once you get the data into a hash table, generating custom LVM reports should be trivial.

Caveats: I saw the module a while back but haven't actually tried it. Also, it appears to be based on LVMv1, so may cause problems on 11i v3.

Take a look at http://search.cpan.org/~cwhite/HPUX-LVM_0.06/LVM.pm. There's a complete sample script at the top of the page.

Other related CPAN modules include:
HPUX::Ioscan.pm
HPUX::FS.pm
HPUX::LVM.pm

If you have 11i v3 vith the latest version of LVM, there's a new option on vgdisplay that displays VG information in a format that's easier to parse with perl/awk/etc:

vgdisplay -F

Darren