On Mon, 11 Dec 2000, Dan Sugalski wrote:

> At 11:15 AM 12/11/00 -0800, [EMAIL PROTECTED] wrote:
>
>
> >I would like to call F$GETDVI from within a script. Now, while I'm an old
> >hand at VMS/DCL, I'm just picking up Perl (took a couple of two-day
> >classes) and I'm not quite sure how to do this. Can anyone share a couple
> >of lines of perl to, say, get the total number of blocks on a disk device
> >on the local host?
>
> The simplest way would be:
>
>    chomp($blocks = `write sys\$output f\$getdvi("disk\$foo", "FREEBLOCKS")`);
>
> but that has the disadvantage of spawning off a subprocess to execute the
> DCL command.

Here is a perl implementation of a unix df utility that comes complete
with the latter disadvantage (this is another test of my recently ruined
email setup BTW):

#!/usr/local/bin/perl

# header format on VMS:

#
#Device                  Device           Error    Volume         Free  Trans Mnt
# Name                   Status           Count     Label        Blocks Count Cnt

# output with no extra controller:
#219373$DIA0:            Mounted              0  OPENVMS062      871716   445   1

# output with extra controller:
#$2$DKA600:       (SHY)  Mounted              0  AXPVMSSYS       847017    14   1

my @raw_disks = `SHOW DEVICES/MOUNTED D`;
my @disks = @raw_disks[3..$#raw_disks];  # skip blank and two header lines
print
"Filesystem              512-blocks        Used   Available Capacity  Mounted on\n";

for (@disks) {
    my @fields = split(/\s+/,$_);
    my $blocks  = `write sys\$output f\$getdvi(\"$fields[0]\",\"MAXBLOCK\")`;
    my ($sys, $avail, $vol_label, $cap) =
         ($fields[0], $fields[4], $fields[3], '-');
    if ($fields[1] =~ /\(/) {
        $sys .= " $fields[1]";
        $avail = $fields[5];
        $vol_label = $fields[4];
    }
    my ($format) = ("%-18s       %9d   %9d   %9d   %3s%%    %s\n");
    if ($blocks > 0) {
        $cap = 100.0 * (($blocks - $avail)/$blocks);
        $format = "%-18s       %9d   %9d   %9d   %3d%%    %s\n";
    }
    printf($format,
        $sys,
        $blocks,
        $blocks - $avail,
        $avail,
        $cap,
        "DISK\$$vol_label");
}

__END__

=pod

=head1 NAME

    B<df> - display free disk space

=head1 SYNOPSIS

    B<df> [-hiklnP] [-t type] [I<file> | I<file_system> ...]

=head1 DESCRIPTION

B<df> displays statistics about the amount of free disk space on the
specified I<file_system> or on the file system of which I<file> is a part.
Values are displayed in 512-byte per block block counts.  If neither
a file nor a file_system operand is specified, statistics for all
mounted file systems are displayed (subject to the -l and -t options below).

The following options are available:

=over 4

=item -h

Human-e reported in 512-bytems with the
MNT_LOCAL flag set. If a non-local file system is given as an ar-
gument, a warning              to provide statisti the possibly
stale statistics that
             were previously obtained.

=item -i

=item -k

=item -l

=item -n

=item -P

Print out information in

=back

=head1 ENVIRONMENT

=over 4

=item BLOCKSIZE

If the environment variable BLOCKSIZE is set, and the -k
option is not specified, the block counts will be displayed
in units of that size block.

=back

=head1 SEE ALSO

L<du>.

=head1 AUTHOR

Peter Prymmer

=head1 HISTORY

=head1 LICENSE

=cut


Reply via email to