From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 26-MAY-1992 02:17:51.38
To:	info-vax@kl.sri.com
CC:	
Subj:	Re: Removing Student Usernames

In article <01GK6V7C49GWDCQFU3@RCNVMS.RCN.MASS.EDU>, 
   DLEE@RCNVMS.RCN.MASS.EDU ("DANIEL F. LEE") writes:
> Is there a procedure that anybody might have to delete student usernames
> at the end of a semester.  I find that when removing a single username
> I must delete all files from the directory tree (lower levels - higher).
> Then, of course, removing the disk quota entry and UAF entry.  I have
> thousands of usernames to delete and would like to automate the procedure.
> Can anybody provide me with some useful info.

We use the following procedures  (the first calls the second to delete
a directory tree).

A command procedure structured as follows can be submitted to do a big
list of users...

$ @DELUSER user1 YES
$ @DELUSER user2 YES  etc. etc.

Regards,

Bruce.
===============================================================================
     __                     __                        E   D I N B U R G H   E D
    /  )         _  _      /  ` ._/_/ . _  _  __     D I N   B U R G H   E D I
   /--<  /`~/ / / )/_)    / _. / / / / / )/ )(      I N B U R   G H   E D I N
  /___/ /  (_/ (_ (_     (__/ / / / / / /(_/__)    N B U R G H     E D I N B
 Dept. of Geography, Univ. of Edinburgh ._/       B U R G H   E D   I N B U
 Drummond Street, Edinburgh, EH8 9XP, Scotland.  U R G H   E D I N B   U R
 E-mail: BRUCE@GEOVAX.ED.AC.UK  Phone: (0)31-650 2558
===============================================================================

$!   Govt. Health Warning!!
$!
$!       The operation of this procedure is dangerous,  and assumptions have 
$!       been made which may change with future releases of VMS.
$!       (relating to format of SYSUAF and MAIL_PROFILE)
$!
$!       Bruce M. Gittings, 1989.
$!
$ IF .NOT. F$PRIV("BYPASS") THEN GOTO ERROR3
$ ON WARNING THEN CONTINUE
$ USER = P1
$ IF USER .EQS. "" THEN INQUIRE USER "_User"
$ IF USER .EQS. "" THEN EXIT
$ ON CONTROL_Y THEN CONTINUE
$ FULLUSER[0,31] := 'USER'
$ OPEN/READ/SHARE=WRITE SYSUAF SYS$SYSTEM:SYSUAF.DAT
$ READ/KEY="''FULLUSER'"/ERROR=ERROR1 SYSUAF RECORD
$ CLOSE/NOLOG SYSUAF
$ ON CONTROL_Y THEN EXIT
$ DISK = F$EDIT(F$EXTRACT(117,30,RECORD),"COLLAPSE")
$ ROOT = F$EDIT(F$EXTRACT(149,30,RECORD),"COLLAPSE")
$ PATH = DISK + ROOT
$ WRITE SYS$OUTPUT ""
$ WRITE SYS$OUTPUT "------------------------------------------------------------------------------"
$ WRITE SYS$OUTPUT "Deleting User ''USER' and directory ''PATH..."
$ SAVE_DIR = F$ENVIRONMENT("DEFAULT")
$!
$!     Remove all his files
$!
$ IF P2 THEN GOTO DELETE_REGARDLESS
$ IF F$SEARCH("''PATH'*.*") .EQS. "" THEN GOTO DELETE_REGARDLESS
$ DIRECTORY 'PATH'
$ INQUIRE REPLY "********>>>>  Delete these files (Y/N)?  [N]"
$ IF .NOT. REPLY THEN GOTO DELETE_USER
$ DELETE_REGARDLESS:
$!
$ ON CONTROL_Y THEN CONTINUE
$!
$!    This is GEOVAX specific...
$ @ADMIN:DELTREE 'PATH'
$!
$!     Remove his base directory
$!
$ DIR = ROOT
$ DIRNAME = ROOT - "[" - "]"
$ CHECK_FOR_END:
$   LASTBIT = F$ELEMENT(1,".",DIR)
$   IF LASTBIT .EQS. "." THEN GOTO DEL_DIR
$   DIR = DIR - ".''LASTBIT'"
$   DIRNAME = LASTBIT - "]"
$ GOTO CHECK_FOR_END
$ DEL_DIR:
$   IF ROOT .EQS. "[''DIRNAME']" THEN PATH = "''DISK'[000000]"
$   DIRECTORY = PATH - ".''DIRNAME'" + DIRNAME + ".DIR;*"
$   DELETE 'DIRECTORY'
$!
$!  Remove Username, disk quota on default disk and network authorisation
$!
$ DELETE_USER:
$   OPEN/WRITE FILE SYS$LOGIN:DELUSER.TMP
$   REAL_DISK = DISK - ":"
$!Following fails - need a mecahnism for identifying true disk?
$!  REAL_DISK = F$PARSE(F$TRNLNM(REAL_DISK),,,"DEVICE")
$   WRITE FILE "$ WRITE SYS$OUTPUT ""Removing Quota from disk ''REAL_DISK'..."""
$   WRITE FILE "$ RUN DISKQUOTA"
$   WRITE FILE "USE ''REAL_DISK'"
$   WRITE FILE "REMOVE ''USER'"
$   WRITE FILE "EXIT"
$   WRITE FILE "$ WRITE SYS$OUTPUT ""Removing User from SYSUAF..."""
$   WRITE FILE "$ AUTHOR := $AUTHORIZE
$   WRITE FILE "$ AUTHOR REMOVE ''USER'"
$   CLOSE FILE
$   SET DEF SYS$SYSTEM:
$   @SYS$LOGIN:DELUSER.TMP
$!
$!    Remove him from Central MAIL data file
$!
$ OPEN/READ/WRITE/SHARE=WRITE MAILUAF SYS$SYSTEM:VMSMAIL.DAT
$ READ/DELETE/KEY="''FULLUSER'"/ERROR=ERROR2 MAILUAF DUMMY
$ CLOSE/NOLOG MAILUAF
$ MAIL_ERROR_CONTINUE:
$   DELETE/NOLOG SYS$LOGIN:DELUSER.TMP;
$   WRITE SYS$OUTPUT "------------------------------------------------------------------------------"
$   SET DEFAULT 'SAVE_DIR'
$   EXIT
$
$ ERROR1:
$   WRITE SYS$OUTPUT "--- Invalid Username - ""''USER'"" is not a user on this system"
$   CLOSE/NOLOG SYSUAF
$   EXIT
$
$ ERROR2:
$   WRITE SYS$OUTPUT "--- There was a problem locating ""''USER'"" in SYS$SYSTEM:MAILUAF.DAT"
$   GOTO MAIL_ERROR_CONTINUE
$
$ ERROR3:
$   WRITE SYS$OUTPUT "--- Sorry, you must have ""BYPASS"" privilege before running DELUSER"
$   EXIT
$!
$!   Routine to Delete Unwanted Users  -     @DELUSER  P1 P2
$!      (B.M. Gittings - 23-OCT-1988)
$!
$!      P1 = Username,  If P2 is TRUE then files are automatically deleted
$!
$!      UIC must be in alphanumeric form, if numeric will be left
$!      Default device and Root Directory read directly from SYSUAF.DAT
$!
------  You also need DELTREE.COM which follows -------------------------------

$ ON CONTROL_Y THEN GOTO DONE
$ DEFAULT=F$ENVIRONMENT("DEFAULT")
$ IF P1 .EQS. "" THEN INQUIRE P1 "Root"
$ IF F$PARSE(P1) .EQS. "" THEN GOTO DONE
$ SET DEFAULT 'P1'
$LOOP:
$ FILESPEC=F$SEARCH("*.DIR")
$ IF FILESPEC .EQS. "" THEN GOTO LOOPEND
$ @ADMIN:DELTREE [.'F$PARSE(FILESPEC,,,"NAME")']
$ GOTO LOOP
$LOOPEND:
$ IF F$SEARCH("*.*;*") .NES. "" THEN DELETE/LOG/NOCONFIRM *.*;*
$ DIR=(F$DIRECTORY()-"]"-">")-(F$PARSE("[-]",,,"DIRECTORY")-"]"-">")-"."
$DONE:
$ SET DEFAULT 'DEFAULT'

--------  End of Message ------------------------------------------------------

