From:	SMTP%"dwing@uh01.colorado.edu" 27-AUG-1993 09:36:53.64
To:	EVERHART
CC:	
Subj:	Re: Lexical calls for obtaining DISKQUOTA information?

X-Newsgroups: comp.os.vms
From: dwing@uh01.colorado.edu (Dan Wing)
Subject: Re: Lexical calls for obtaining DISKQUOTA information?
Message-Id: <1993Aug25.235659.26385@colorado.edu>
Sender: news@colorado.edu (The Daily Planet)
Nntp-Posting-Host: buckie.hsc.colorado.edu
Reply-To: dwing@uh01.colorado.edu
Organization: University of Colorado Hospital Authority, Denver
Date: Wed, 25 Aug 1993 23:56:59 GMT
Lines: 215
To: Info-VAX@kl.sri.com
X-Gateway-Source-Info: USENET

In article <25g2rp$97@paperboy.ids.net>, green@ids.net (Andy Green) writes:

>Does anyone know if there are any DCL Lexical commands that can obtain
>information on a users disk quota?

This .COM file relies on the output of SHOW QUOTA -- if it changes when you
upgrade VMS, this .COM file will have to be tweaked.  When called, it will 
return you disk quota on a specific device, and, optionally, will mail a 
notice to user(s) if your quota (or the device itself) has less that a certain 
number of available blocks.

-Dan Wing, Systems Administrator, University Hospital, Denver
 dwing@uh01.colorado.edu or wing_d@ucolmcc.bitnet

-----

$! DISK_QUOTA.COM  --  check the current process' available disk quota,
$!                     inform programmers if below value.
$  VERIFY = F$VERIFY("''DISK_QUOTA_DEBUG'")
$  GOTO SKIP_COMMENTS
$!
$! Created by Dan Wing, Central Washington University,
$! Auxiliary Services Computing
$!
$! This returns the available disk quota into the symbol DISK_QUOTA_AVAILABLE.
$! (If the user is Overdrawn, or another problem exists, then 0 is returned.)
$!
$! Imports:
$!   P1  Disk unit (DISK124, DISKA, etc.)
$!   P2  Minumum disk quota (optional)
$!   P3  Users to mail low-quota message to (optional)
$!   P4  Filename calling DISK_QUOTA, for inclusion into mail msg (optional)
$!   P5  UIC to check (optional).  If this isn't your username, you need
$!       SYSPRV (actually, you need READ access to QUOTA.SYS, but SYSPRV is
$!       what this .COM file checks)
$!
$! If the logical name DISK_QUOTA_QUIET equates to a true value, no 'normal'
$! messages are displayed (errors are always displayed).
$!
$! Exports:
$!   DISK_QUOTA_OK         True/False, depends on user's quota compared to P2
$!   DISK_QUOTA_AVAILABLE  Users available disk quota
$!
$!
$! If the available blocks on the disk is lower than the user's quota, the
$! available blocks are returned.
$!
$! Sample calls to DISK_QUOTA:
$!   @DISK_QUOTA  DISKA:  40000  WINGD  'F$ENVIRONMENT("PROCEDURE")'
$!   @DISK_QUOTA  DISKA:  30000
$!   @DISK_QUOTA  LIVEDATA:
$!   @DISK_QUOTA  UPLOAD$DIRECTORY 20000 WINGD 'F$ENVIRONMENT("PROCEDURE")'
$!   @DISK_QUOTA  SYS$LOGIN: 20000 WINGD,SYSTEM "" [IS_DEPARTMENT]
$!
$!
$! REVERSE CHRONOLOGICAL MODIFICATION HISTORY
$!
$!     Date     By   Version    Description
$!  ----------  ---  -------    -----------
$! 28-DEC-1992  DGW  VMS 5.5-1  P5 (UIC) added.
$! 20-NOV-1990  DGW  VMS 5.3    Leave DISK_QUOTA on error if error occurs
$! 21-AUG-1990  DGW  VMS 5.3    Output to file w/SYS$OUTPUT and SYS$ERROR
$!                              (using one only outputs to .LOG or screen)
$!  3-AUG-1990  DGW  VMS 5.3    Correctly handle error of "quotas not enabled 
$!                              on this volume."
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$
$SKIP_COMMENTS:
$  ON WARNING THEN GOTO _ERROR
$
$  SET SYMBOL/SCOPE=(noGLOBAL)/VERB          ! we set global symbols later
$  UIC = F$USER()
$
$  SAY := WRITE SYS$OUTPUT
$  IF F$TRNLNM("DISK_QUOTA_QUIET") THEN SAY = "!"
$! (if the above substitution (with "!") takes place, you can't use line-
$!  continuation characters on lines with SAY...)
$
$  IF (P5 .NES. "") .AND. ((P5 .NES. UIC) .AND. (.NOT. F$PRIVILEGE("SYSPRV"))) THEN -
     GOTO _NO_PRIV
$
$  IF P5 .EQS. "" THEN P5 = UIC
$
$  IF P1 .EQS. "?" THEN GOTO _HELP
$  IF P1 .EQS. "" THEN GOTO _MISSING_OPTIONS
$
$  FILENAME = "SYS$SCRATCH:QUOTA_" + F$GETJPI("","PID") + ".TMP;"
$
$  SAY F$FAO("!/... Checking disk quota on !AS for user !AS.", P1, P5)
$
$  TMP_VERIFY = F$VERIFY(0)   ! Verify messes this part up ...
$  DEFINE/noLOG SYS$OUTPUT 'FILENAME'
$  DEFINE/noLOG SYS$ERROR 'FILENAME'
$  SET noON
$  SHOW QUOTA/DISK='P1'/USER='P5'
$  STATUS = $STATUS
$  SET ON
$  DEASSIGN SYS$OUTPUT
$  DEASSIGN SYS$ERROR
$  TMP_VERIFY = F$VERIFY(TMP_VERIFY)
$
$  OPEN/READ FILE 'FILENAME'                 
$  READ FILE RECORD                          ! get first line
$  CLOSE FILE
$
$  DELETE 'FILENAME'
$
$  OFFSET = F$LOCATE ("used,", RECORD) + 6
$  STOP   = F$LOCATE ("available", RECORD)
$
$  DISK_QUOTA_AVAILABLE == F$INTEGER (F$EXTRACT (OFFSET, STOP-OFFSET, RECORD))
$  DISK_QUOTA_OK :== TRUE
$
$  IGNORE_ERROR := FALSE
$
$  IF STATUS .EQ. %X000003D4  ! %SYSTEM-F-QFNOTACT
$  THEN
$    SAY F$FAO("Disk Quotas are not enabled on device !AS", P1)
$    DISK_QUOTA_AVAILABLE == F$GETDVI(P1,"FREEBLOCKS")
$    IGNORE_ERROR := TRUE
$  ENDIF
$
$  IF STATUS .EQ. %X000003E4
$  THEN
$    SAY F$FAO("No disk quota entry for user !AS", P5)
$    DISK_QUOTA_AVAILABLE == 0
$    IGNORE_ERROR := TRUE
$  ENDIF
$  
$  IF F$GETDVI(P1,"FREEBLOCKS") .LT. DISK_QUOTA_AVAILABLE 
$  THEN 
$    SAY F$FAO("Device !AS has only !UL blocks free.", P1, F$GETDVI(P1,"FREEBLOCKS"))
$    DISK_QUOTA_AVAILABLE == F$GETDVI(P1,"FREEBLOCKS") 
$  ENDIF
$
$  IF (.NOT. STATUS) .AND. (.NOT. IGNORE_ERROR) THEN GOTO _KNOWN_ERROR
$
$  SAY F$FAO("!/User !AS has !UL blocks available on !AS", P5, DISK_QUOTA_AVAILABLE, P1)
$
$  IF F$TYPE(P2) .EQS. "INTEGER" .AND. DISK_QUOTA_AVAILABLE .LE. F$INTEGER(P2)
$  THEN
$    DISK_QUOTA_OK :== FALSE          ! not enough quota..
$    SAY F$FAO("which is less than the specified minimum of !AS.", P2)
$
$    IF P3 .NES. ""
$    THEN
$      IF P4 .EQS. "" THEN P4 = "(no program specified.  SYS$INPUT is " + -
     F$TRNLNM("SYS$INPUT") + ")"
$      SAY "... mailing notification to ''P3'."
$      MAILFILE = "SYS$SCRATCH:MAIL_" + F$GETJPI("","PID") + ".TMP;"
$      OPEN/WRITE FILE 'MAILFILE'
$      WRITE FILE F$FAO("Disk quota for UIC !AS is below the specified minimum value.", P5)
$      WRITE FILE ""
$      WRITE FILE F$FAO("  Device:            !AS (!AS, !AS, !AS)", -
          P1, -
          F$GETDVI(P1,"LOGVOLNAM"), -
          F$GETDVI(P1,"VOLNAM"), -
          F$GETDVI(P1,"ALLDEVNAM"))
$      WRITE FILE       "  Device freeblocks: ", F$GETDVI(P1,"FREEBLOCKS")
$      WRITE FILE ""
$      WRITE FILE "  Minimum quota:     ", P2
$      WRITE FILE "  Quota available:   ", DISK_QUOTA_AVAILABLE
$      WRITE FILE ""
$      WRITE FILE ""
$      WRITE FILE "This message sent by a ''F$MODE()' call to DISK_QUOTA from:"
$      WRITE FILE P4
$      CLOSE FILE
$      MAIL 'MAILFILE' 'P3' -
          /SUBJECT="Low disk quota" -
          /PERSONAL="DISK_QUOTA: Low disk quota"
$      DELETE 'MAILFILE'
$    ENDIF
$  ENDIF
$
$  SAY ""
$
$_END:
$  VERIFY = F$VERIFY(VERIFY)
$  EXIT   ! Leaving DISK_QUOTA ...
$
$_ERROR:
$  STATUS = $STATUS
$_KNOWN_ERROR:
$  WRITE SYS$OUTPUT "Unexpected error occurred in DISK_QUOTA."
$  WRITE SYS$OUTPUT "Error was: ", STATUS, ", ", F$MESSAGE(STATUS)
$  VERIFY = F$VERIFY(VERIFY)
$  EXIT STATUS      ! Leaving DISK_QUOTA (on error) ...
$
$_HELP:
$  TYPE SYS$INPUT

DISK_QUOTA -- checks the user's disk quota.

Imports:
  P1  Disk unit (DISK124, DISKA, etc.)
  P2  Minumum disk quota (optional)
  P3  Users to mail low-quota message to (optional)
  P4  Filename calling DISK_QUOTA, for inclusion into mail msg (optional)
         (see example in DISK_QUOTA.COM header)
  p5  UIC to check (if other than your own; requires SYSPRV)

Exports:
  DISK_QUOTA_OK         True/False, depends on user's quota compared to P2
  DISK_QUOTA_AVAILABLE  Users available disk quota (numeric)

$  GOTO _END
$
$_MISSING_OPTIONS:
$  WRITE SYS$OUTPUT "Missing disk-name parameter P1; use ? for help."
$  GOTO _END
$
$_NO_PRIV:
$  WRITE SYS$OUTPUT "Specifying a UIC other than your own requires SYSPRV."
$  GOTO _END

