Re: VMS script that provides disk usage similar to Unix df command (423 Views)
Reply
Regular Advisor
Tom Wolf_3
Posts: 232
Registered: ‎03-11-2005
Message 1 of 7 (474 Views)

VMS script that provides disk usage similar to Unix df command

Hello all.

We have a single OpenVMS V8.3-1H1 server running on HP rx2660 hardware in our environment.

All our other servers are Unix and Linux machines.

I'm trying to come up with a script for the VMS server that will display output similar to the Unix/Linux "df" command, which gives disk utilization.

On our Unix/Linux servers, output of the "df" command is as follows.

 

 

$ df -h
Filesystem                 Size  Used  Avail  Capacity Mounted on
/dev/vg00/lvol3            1.1G  445M   701M     39%   /
/dev/vg00/lvol1            1.1G  407M   739M     36%   /stand
/dev/vg01/lvxtra           2.0G  938M   1.1G     46%   /xtra
/dev/vg00/lvol7            6.0G  4.5G   1.5G     75%   /var
/dev/vg00/lvol6            8.0G  3.5G   4.5G     44%   /usr
/dev/vg00/lvol5            1.0G   19M   997M      2%   /tmp
/dev/vg00/lvol4            7.0G  5.5G   1.5G     79%   /opt
/dev/vg01/lvhome           512M   18M   490M      4%   /home

 

Could someone please provide some guidance on creating a VMS script that will report disk usage is this format.

That is, the device name, it's size, amount of space used, amount of space available (in GB and MB where appropriate), as well the usage percentage and volume label.

 

I'm familiar with the "show device /full /units=bytes" command and I'm guessing the output of this command could be used to parse out selected data and generate a report similar to "df" but I'm not certain how to go about it.

Again, any assistance on this would be really helpful.

 

Thanks in advance.

 

Tom Wolf

Please use plain text.
Trusted Contributor
John McL
Posts: 280
Registered: ‎02-24-2008
Message 2 of 7 (466 Views)

Re: VMS script that provides disk usage similar to Unix df command

If you want to do it in DCL you'll need lexical function F$GETDVI (...).  If you want it to run faster then write it in some language, even Macro, and use SYS$GETDVI.

 

Look up the help on both the above to see the details.

Please use plain text.
Honored Contributor
Steven Schweda
Posts: 9,062
Registered: ‎02-23-2005
Message 3 of 7 (457 Views)

Re: VMS script that provides disk usage similar to Unix df command

Please use plain text.
Regular Advisor
Tom Wolf_3
Posts: 232
Registered: ‎03-11-2005
Message 4 of 7 (451 Views)

Re: VMS script that provides disk usage similar to Unix df command

Thank you Steven for those files.

Very helpful.

Please use plain text.
Honored Contributor
John Gillings
Posts: 2,992
Registered: ‎07-31-2003
Message 5 of 7 (442 Views)

Re: VMS script that provides disk usage similar to Unix df command

[ Edited ]

Tom,

   Here's a rough cut. DCL is hopeless with decimal arithmetic, so getting the decimals in the sizes is a problem. This code kind of works, but fractional parts are truncated rather than rounded.

 

If the spacing is critical, you may need to play with the formatting (what does the unix command do if the size evaluates to between 1000 and 1024?)

 

df.com

 

$!   Filesystem                 Size  Used  Avail  Capacity Mounted on
$!   1234567890123456789012345678901234567890123456789012345678901234567890
$  fmt="!24AS!7AS!7AS!7AS     !3AS"
$  WRITE SYS$OUTPUT "Filesystem                 Size   Used  Avail  Capacity Mounted on"
$  DiskLoop: disk=F$DEVICE("*''p1'*","DISK")-"_"-":"
$    IF disk.NES.""
$    THEN
$!        Skip devices that are not mounted or are shadow set members
$      IF F$GETDVI(disk,"MNT").AND..NOT.F$GETDVI(disk,"SHDW_MEMBER")
$      THEN
$        MaxBlock=F$GETDVI(disk,"MAXBLOCK")/2             ! Convert to KB
$        FreeBlocks=F$GETDVI(disk,"FREEBLOCKS")/2
$        Avail=MaxBlock-FreeBlocks
$        Percent=F$FAO("!2UL%",FreeBlocks/(MaxBlock/100))
$        s=MaxBlock
$        GOSUB HumanSize
$        MaxBlock=v
$        s=FreeBlocks
$        GOSUB HumanSize
$        FreeBlocks=v
$        s=Avail
$        GOSUB HumanSize
$        Avail=v
$        WRITE SYS$OUTPUT F$FAO(fmt,disk,MaxBlock,FreeBlocks,Avail,Percent)
$      ENDIF
$      GOTO DiskLoop
$    ENDIF
$ EXIT
$
$ HumanSize:
$   i=0
$   Prefix="KMGTPEZY"
$   dec=""
$   RangeLoop:
$     IF s.LT.1024
$     THEN
$       v=F$FAO("!4UL!AS!AS",s,dec,F$EXTRACT(i,1,Prefix))
$       RETURN
$     ENDIF
$     m=s/1024
$     dec=F$FAO(".!1UL",(s-m*1024)/(1024/10))
$     s=m
$   i=i+1
$   GOTO RangeLoop

 

Example:

 

$ @df
Filesystem                 Size   Used  Avail  Capacity Mounted on
DSA30                     15.0G   7.9G   7.0G     53%
DSA31                     15.0G   2.0G  12.9G     13%
DSA32                     15.0G  14.9G 103.8M     99%
DSA42                     30.0G  14.8G  15.2G     49%
DSA44                     30.0G  20.9G   9.0G     69%
DSA45                     75.0G  62.9G  12.0G     83%
DSA46                    100.0G  99.7G 269.8M     99%
DSA100                    20.0G   4.9G  15.0G     24%

 

A crucible of informative mistakes
Please use plain text.
Esteemed Contributor
H.Becker
Posts: 356
Registered: ‎04-09-2009
Message 6 of 7 (423 Views)

Re: VMS script that provides disk usage similar to Unix df command

I know, you asked for a script, and I kown it's not the wheel, but there is already some code in GNV. You may want to  use the supplied executable or checkout the source code. Getting/using the executable (for Alpha, I don't have access to an I64 system) can be as easy as fetching the PCSI file and:                                                  
                                                                                
$ prod extr file gnv/source=DSA110:[ALPHA.OPENVMS.GNV.V30-1]/sel=df.exe/dest=[]
                                                                                
Performing product kit validation of signed kits ...                            
%PCSI-I-VALPASSED, validation of DSA110:[ALPHA.OPENVMS.GNV.V30-1]DEC-AXPVMS-GNV$
V0300-001-1.PCSI$COMPRESSED;1 succeeded                                         
                                                                                
The following product has been selected:                                        
    DEC AXPVMS GNV V3.0-1                  Layered Product                      
                                                                                
Do you want to continue? [YES]                                                  
                                                                                
Portion done: 0%...100%                                                         
$ mc []df -h                                                                    
Filesystem            Size  Used Avail Use% Mounted on                          
_DSA110:               20G   20G   70M 100% _DSA110:                            
_DSA115:               20G   20G  179M 100% _DSA115:                            
_DSA153:              8.5G  6.7G  1.9G  79% _DSA153:                            
_DSA200:              4.0G  2.2G  1.9G  53% _DSA200:                            
...

Please use plain text.
Regular Advisor
Tom Wolf_3
Posts: 232
Registered: ‎03-11-2005
Message 7 of 7 (389 Views)

Re: VMS script that provides disk usage similar to Unix df command

Thanks again to all those that responded.

Some very useful info here for a VMS novice.

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation