From: DWING@UH01.Colorado.EDU (Dan Wing)
Newsgroups: comp.os.vms
Subject: Re: Can I change quota entries from DCL or a program?
Date: 28 Jul 92 22:38:37 GMT
Distribution: world
Organization: The Internet

Bob Boag, boag@marshall.wvnet.edu, wrote:

>I'm trying to design an application which allows specific users to adjust
>quotas for other users. I'd like to be able to do this without writing SHOW
>QUOTA to a file and then parsing it and generating commands for SYSMAN to
>adjust the quota.
>
>I know that ALL-IN-1 somehow checks your quota - anyone know if it does
>anything fancy besides parsing the output of a SHOW QUOTA or SYSMAN command?

Here's a program to parse the output of SHOW QUOTA.  It had a different
application, but should be fairly easy to modify to do SHOW QUOTA/USER=[x,y]

-Dan Wing, DWING@UH01.Colorado.EDU or WING_D@UCOLMCC.BITNET (DGW11)
 Systems Programmer, University Hospital, Denver

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990
$!   On 28-JUL-1992 16:37:30.78   By user DWING
$!
$! This VMS_SHARE Written by:
$!    Andy Harper, Kings College London UK
$!
$! Acknowledgements to:
$!    James Gray       - Original VMS_SHARE
$!    Michael Bednarek - Original Concept and implementation
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$!       1. DISK_QUOTA.COM;3
$!
$set="set"
$set symbol/scope=(nolocal,noglobal)
$f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
$e="write sys$error  ""%UNPACK"", "
$w="write sys$output ""%UNPACK"", "
$ if f$trnlnm("SHARE_LOG") then $ w = "!"
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$UNPACK: SUBROUTINE ! P1=filename, P2=checksum
$ if f$search(P1) .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped."
$ delete 'f'*
$ exit
$file_absent:
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'."
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
$ delete 'f'*
$ exit
$dirok:
$ w "-I-PROCESS, Processing file ''P1'."
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:=
CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b));
LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1);
IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE;
MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1;
ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")=
1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF";
POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r);
ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1;
COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE,
"output_file"));ENDPROCEDURE;Unpacker;QUIT;
$ delete/nolog 'f'*
$ CHECKSUM 'P1'
$ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
$ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ ENDSUBROUTINE
$START:
$ create 'f'
X$! DISK_QUOTA.COM  --  check the current process' available disk quota,
X$!                     inform programmers if below value.
X$  VERIFY = F$VERIFY(0)
X$  GOTO SKIP_COMMENTS
X$!
X$! Created by Dan Wing, Central Washington University,
X$! Auxiliary Services Computing
X$!
X$! This returns the available disk quota into the symbol DISK_QUOTA_AVAILABL
VE.
X$! (If the user is Overdrawn, or another problem exists, then 0 is returned.
V)
X$!
X$! Imports:
X$!   P1  Disk unit (DISK124, DISKA, etc.)
X$!   P2  Minumum disk quota (optional)
X$!   P3  Users to mail low-quota message to (optional)
X$!   P4  Filename calling DISK_QUOTA, for inclusion into mail msg (optional)
X$!
X$! Exports:
X$!   DISK_QUOTA_OK         True/False, depends on user's quota compared to P
V2
X$!   DISK_QUOTA_AVAILABLE  Users available disk quota
X$!
X$!
X$! If the available blocks on the disk is lower than the user's quota, the
X$! available blocks are returned.
X$!
X$! Sample calls to DISK_QUOTA:
X$!   @DISK_QUOTA  DISKA:  40000  WINGD  'F$ENVIRONMENT("PROCEDURE")'
X$!   @DISK_QUOTA  DISK124:
X$!   @DISK_QUOTA  DISKA:  30000
X$!   @DISK_QUOTA  LIVEDATA:
X$!   @DISK_QUOTA  UPLOAD$DIRECTORY 20000 WINGD 'F$ENVIRONMENT("PROCEDURE")'
X$!
X$!
X$! REVERSE CHRONOLOGICAL MODIFICATION HISTORY
X$!
X$!     Date     By   Version    Description
X$!  ----------  ---  -------    -----------
X$! 20-NOV-1990  DGW  VMS 5.3    Leave DISK_QUOTA on error if error occurs
X$! 21-AUG-1990  DGW  VMS 5.3    Output to file w/SYS$OUTPUT and SYS$ERROR
X$!                              (using one only outputs to .LOG or screen)
X$!  3-AUG-1990  DGW  VMS 5.3    Correctly handle error of "quotas not enable
Vd`20
X$!                              on this volume."
X$!
X$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
X$
X$SKIP_COMMENTS:
X$  ON WARNING THEN GOTO _ERROR
X$  IF P1 .EQS. "?" THEN GOTO _HELP
X$  IF P1 .EQS. ""
X$    THEN WRITE SYS$OUTPUT "Missing disk-name parameter P1; use ? for help."
X$         GOTO END
X$    ENDIF
X$
X$  DELETE := DELETE      ! define symbols required locally
X$  MAIL   := MAIL
X$
X$  FILENAME = "SYS$SCRATCH:QUOTA_" + F$GETJPI("","PID") + ".TMP;"
X$  WRITE SYS$OUTPUT ""
X$  WRITE SYS$OUTPUT "... Checking disk quota on ''P1'"
X$
X$  TMP_VERIFY = F$VERIFY(0)   ! Verify messes this part up ...
X$    SET noON
X$      DEFINE/noLOG SYS$OUTPUT 'FILENAME'
X$      DEFINE/noLOG SYS$ERROR 'FILENAME'
X$      SHOW QUOTA/DISK='P1'
X$      STATUS = $STATUS
X$      DEASSIGN SYS$OUTPUT
X$      DEASSIGN SYS$ERROR
X$    SET ON
X$  TMP_VERIFY = F$VERIFY(TMP_VERIFY)
X$
X$  OPEN/READ FILE 'FILENAME'                `20
X$  READ FILE RECORD                          ! read first record
X$  CLOSE FILE
X$
X$  DELETE 'FILENAME'
X$
X$  OFFSET = F$LOCATE ("used,", RECORD) + 6
X$  STOP   = F$LOCATE ("available", RECORD)
X$
X$  DISK_QUOTA_AVAILABLE == F$INTEGER (F$EXTRACT (OFFSET, STOP-OFFSET, RECORD
V))
X$  DISK_QUOTA_OK :== TRUE
X$
X$  IF STATUS .EQ. %X000003D4
X$  THEN
X$    WRITE SYS$OUTPUT "Disk Quotas not enabled on device ''P1'"
X$    DISK_QUOTA_AVAILABLE == F$GETDVI(P1,"FREEBLOCKS")
X$  ELSE
X$    IF F$GETDVI(P1,"FREEBLOCKS") .LT. DISK_QUOTA_AVAILABLE`20
X$    THEN`20
X$      WRITE SYS$OUTPUT "Device ''P1' has only ", F$GETDVI(P1,"FREEBLOCKS"),
V -
X          " blocks free."
X$      DISK_QUOTA_AVAILABLE == F$GETDVI(P1,"FREEBLOCKS")`20
X$    ENDIF
X$  ENDIF
X$
X$  IF F$TYPE(P2) .EQS. "INTEGER" .AND. DISK_QUOTA_AVAILABLE .LE. F$INTEGER(P
V2)
X$  THEN
X$    DISK_QUOTA_OK :== FALSE          ! not enough quota..
X$    WRITE SYS$OUTPUT ""
X$    WRITE SYS$OUTPUT "User ", F$USER(), " has ", DISK_QUOTA_AVAILABLE, -
X          " blocks available on ", P1, ","
X$    WRITE SYS$OUTPUT "which is less than the specified minimum of ''P2'."
X$
X$    IF P3 .NES. ""
X$    THEN
X$      IF P4 .EQS. "" THEN P4 = "(no program specified)"
X$      WRITE SYS$OUTPUT "... mailing notification to ''P3'."
X$      MAILFILE = "SYS$SCRATCH:MAIL_" + F$GETJPI("","PID") + ".TMP;"
X$      OPEN/WRITE FILE 'MAILFILE'
X$      WRITE FILE "This user's disk quota is below the specified minimum val
Vue."
X$      WRITE FILE ""
X$      WRITE FILE "  Device:            ", P1, "  (", -
X          F$GETDVI(P1,"LOGVOLNAM"), ":, ", -
X          F$GETDVI(P1,"VOLNAM"), ", ", -
X          F$GETDVI(P1,"ALLDEVNAM"), ")"
X$      WRITE FILE "  Device freeblocks: ", F$GETDVI(P1,"FREEBLOCKS")
X$      WRITE FILE ""
X$      WRITE FILE "  Minimum quota:     ", P2
X$      WRITE FILE "  Quota available:   ", DISK_QUOTA_AVAILABLE
X$      WRITE FILE ""
X$      WRITE FILE "This message sent by a ''F$MODE()' call to DISK_QUOTA fro
Vm:"
X$      WRITE FILE P4
X$      CLOSE FILE
X$      MAIL 'MAILFILE' 'P3' -
X          /SUBJECT="Low disk quota" -
X          /PERSONAL="DISK_QUOTA: Low disk quota"
X$      DELETE 'MAILFILE'
X$    ENDIF
X$  ELSE
X$    WRITE SYS$OUTPUT ""
X$    WRITE SYS$OUTPUT "User ", F$USER(), " has ", DISK_QUOTA_AVAILABLE, -
X          " blocks available on ", P1, "."
X$  ENDIF
X$
X$  WRITE SYS$OUTPUT ""
X$
X$END:
X$  VERIFY = F$VERIFY(VERIFY)
X$  EXIT   ! Leaving DISK_QUOTA ...
X$
X$_ERROR:
X$  STATUS = $STATUS
X$  WRITE SYS$OUTPUT "Error occurred in DISK_QUOTA."
X$  VERIFY = F$VERIFY(VERIFY)
X$  EXIT STATUS      ! Leaving DISK_QUOTA (on error) ...
X$
X$_HELP:
X$  TYPE SYS$INPUT
X
XDISK_QUOTA -- checks the user's disk quota.
X
XImports:
X  P1  Disk unit (DISK124, DISKA, etc.)
X  P2  Minumum disk quota (optional)
X  P3  Users to mail low-quota message to (optional)
X  P4  Filename calling DISK_QUOTA, for inclusion into mail msg (optional)
X         (see example in DISK_QUOTA.COM header)
X
XExports:
X  DISK_QUOTA_OK         True/False, depends on user's quota compared to P2
X  DISK_QUOTA_AVAILABLE  Users available disk quota (numeric)
X
X$  GOTO END
$ CALL UNPACK DISK_QUOTA.COM;3 138105739
$ v=f$verify(v)
$ EXIT

Newsgroups: comp.os.vms