From:	CSBVAX::MRGATE!RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP 15-AUG-1988 07:14
To:	ARISIA::EVERHART
Subj:	SUM (Show Users More) Part 3 of 4


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Fri, 12 AUG 88 21:54:15 PDT
Received: from hac2arpa.hac.com by KL.SRI.COM with TCP; Fri, 12 Aug 88 21:53:26 PDT
Received: from draco.HAC.COM by hac2arpa.hac.com (3.2/SMI-DDN)
	id AA13272; Fri, 12 Aug 88 21:58:48 PDT
Received: by draco id <24C20638024@draco.HAC.COM> ;
       Fri, 12 Aug 88 21:54:26 PDT
Date: Fri, 12 Aug 88 21:54:24 PDT
From: Michael N. Kimura <MNK@draco.hac.com>
Subject: SUM (Show Users More) Part 3 of 4
To: info-vax%kl.sri.com@hac2arpa.hac.com
X-Vms-Mail-To: EXOS%"<info-vax%kl.sri.com@hac2arpa.hac.com>",MNK
Message-Id: <880812215424.24C20638024@draco.HAC.COM>

+-+-+-+ Beginning of part 3 +-+-+-+
X$!"===========================================================================
X$!" Execute SUM
X$!
X$`009sum 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8'
X$!
X$!"===========================================================================
X$!" exit and cleanup
X$!
X$l_exit:
X$`009status = $status
X$`009priv_list = f$setprv(priv_list)
X$!
X$`009exit `009'status'+(0*f$verify(verify))
$ GOSUB UNPACK_FILE
$ FILE_IS = "SUM.HLP"
$ CHECKSUM_IS = 1580286459
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X1 SUM
X  Displays the terminal name (physical device name if terminal is a
X  virtual terminal, remote node name and port name if terminal is a
X  LAT device),  username,  and  process  identification code  (PID)
X  of either specific  interactive users or all interactive users on
X  the system.
X
X  Format:
X
X
X    SUM  [username]
X2 Parameters
X
X username
X
X  Specifies the user about whom you want information.  If you  specify
X  a  string,  the  system  lists all interactive users whose usernames
X  begin with the specified character  string.   For  example,  if  the
X  string  MAR  is  specified  as a username, a list of all interactive
X  users whose usernames begin with  MAR  is  displayed.   If  no  user
X  exists  whose  username  matches  the  specified username string, an
X  error message is displayed.
X
X  If you omit this parameter, a  list  of  all  interactive  users  is
X  displayed.
X2 Command_Qualifiers
X
X/FULL
X  /FULL
X  /NOFULL (default)
X
X Requests  that  the  full  physical device name of a terminal and the
X full remote node name of a terminal server be  displayed  instead  of
X the  default  which  is to display only the first eight characters of
X the physical device name and the first six characters of  the  remote
X node name.
X/OUTPUT
X /OUTPUT[=file-spec]
X /NOOUTPUT
X
X  Controls where the output of the command is sent.   If  you  do  not
X  enter  the  qualifier,  or  if  you  enter  /OUTPUT  without  a file
X  specification, the output is sent to  the  current  process  default
X  output stream or device, identified by the logical name SYS$OUTPUT.
X  If you enter /OUTPUT with a partial file specification (for example,
X  specifying  only a directory), SUM  is the default file name and LIS
X  the default file type.  If you enter a file  specification,  it  may
X  not include any wildcard characters.
X
X  If you enter /NOOUTPUT, output is suppressed.
X
X2 Examples
X
X  1.   $ SUM
X                 VAX/VMS Interactive Users
X                   4-FEB-1985 12:48:51.14
X           Total number of interactive users = 14
X        
X          PID    Username     Process Name    Terminal
X        202000B3 <login>      _VTA9:          VTA9:   TTA7:
X        204000C4 AHO          AHO             VTA21:  LTA1878: LYRA03 PORT_7
X        2040013A ETZEL        M Etzel VTA43:  VTA43:  LTA1710: LYRA06 PORT_6
X        20400138 FRISSELLE    FRISSELLE       VTA42:  LTA1801: LYRA03 PORT_8
X        20400095 HOBBS        cw hobbs        VTA1:   Disconnected
X        204000DC HUANG        _VTA32:         VTA32:  LTA11:   DORADO PORT_8
X        204000B9 KUEHN        KUEHN           VTA14:  TTB0:
X        20400123 MALIK        MALIK           VTA38:  TTB6:
X        20400113 MCLAUGHLIN   MCLAUGHLIN      VTA35:  LTA1838: LYRA04 PORT_1
X        204000BC MURRAY       MURRAY          VTA16:  LTA1659: LYRA11 PORT_1
X        204000C2 OPERATOR     OPERATOR        VTA20:  OPA0:
X        2040012C PERRON       PERRON          VTA40:  TTA4:
X        2040013D POLLACK      POLLACK         VTA45:  TTA3:
X        20400097 STEEVES      STEEVES         VTA2:   LTA1876: LYRA10 PORT_5
X
X  The  SUM command displays the process identification code (PID), the
X  user name, process  name,  and  terminal  names  (both  virtual  and
X  physical, plus remote node name and port name of LAT devices) of all
X  interactive users currently on the system.  A user name  of  <login>
X  indicates that someone is in the process of logging in.
X
X  2.   $ SUM GARGARIAN
X                 VAX/VMS Interactive Users
X                  4-FEB-1985 16:45:14.14
X           Total number of interactive users = 32
X          
X          PID    Username     Process Name    Terminal
X        20200115 GARGARIAN    GARGARIAN       VTA35:  LTA1838: LYRA04 PORT_1
X
X  The SHOW USERS command  displays  the  process  identification  code
X  (PID),  the  user  name,  process  name,  and  terminal names of the
X  interactive user GARGARIAN.
X
X  3.   $ SUM J
X                 VAX/VMS Interactive Users
X                  4-FEB-1985 16:45:11.66
X           Total number of interactive users = 32
X         
X          PID    Username     Process Name    Terminal
X        202000DB JACK         JACK            VTA21:  LTA1878: LYRA03 PORT_7
X        2020011D JEFFREYS     JEFFREYS        VTA43:  LTA1710: LYRA06 PORT_6
X
X  The  SUM command displays the process identification code (PID), the
X  user name, process name, and terminal names of all interactive users
X  whose usernames begin with the letter J.
$ GOSUB UNPACK_FILE
$ FILE_IS = "SUMTABLE.CLD"
$ CHECKSUM_IS = 844135288
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X! Module SUM_Table for parsing command line
X
XModule SUM_Table
XIdent "V1.0"
X! Show Us More (SUM)
Xdefine verb SUM
X   parameter P1 , label=USERNAME
X      value
X   qualifier OUTPUT
X      default
X      value (default="SYS$OUTPUT",type=$file)
X   qualifier FULL
$ GOSUB UNPACK_FILE
$ FILE_IS = "SUM_V4.FOR"
$ CHECKSUM_IS = 1529926996
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X!*===========================================================================
X!* Show Users More -- This program mimics VAX/VMS SHOW USERS command but adds
X!*`009`009      the remote node(port) information for LAT terminals
X!*
X!* Environment: User Mode, VAX/VMS Version V4.6 or greater
X!*`009`009(On VAX/VMS Version V5.x and greater you should use new
X!*`009`009version of SUM that uses $GETDVI(DVI$_ACCPORNAM) instead
X!*`009`009of $QIO since $QIO requires access to the terminal therefore
X!*`009`009it requires SHARE and SYSPRV privilege)
X!*
X!* Privileges:  WORLD`009- To get Job/Process Information
X!*`009`009SHARE`009- To assign a channel to a terminal allocated already
X!*`009`009SYSPRV`009- To override LAT terminal protection (after security
X!*`009`009`009  patch has been installed).
X!*
X!* Date:`00913-May-1988
X!*
X!* Author:`009Michael Kimura
X!*
X!*`009`009Hughes Aircraft Company (RSG)
X!*`009`009MS: R2/A159
X!*`009`009P.O. Box 92426
X!*`009`009Los Angeles,  CA  90009
X!*
X!*`009`009(213) 615-9775
X!*
X!*===========================================================================
X
X`009options/extend_source`009`009!* Allow lines longer than 72 chars
X
X`009program sum`009`009`009!* Show Users More
X
X!---------------------------------------------------------------------------
X!* Declarations
X
X`009implicit none`009`009`009!* Declare everything!
X
X`009include '($syssrvnam)'`009`009!* Include System Service Names
X`009include '($ssdef)'`009`009!* Include SS$ codes
X`009include '($dscdef)'`009`009!* Include DSC$ codes
X
X`009include 'ItmLst'`009`009!* Include Item List Structure
X
X`009parameter
X`0091`009IO$_TTY_PORT`009 = '00000029'X,`009!* Terminal Port FDT Routine
X`0091`009IO$M_LT_READPORT = '00000100'X`009!* Read Port IO Function Code
X
X`009parameter
X`0091`009DEF_TT_PHYDEVNAM = 8,`009`009!* Default length of PHYDEVNAM
X`0091`009DEF_REMOTE_NODE = 6`009`009!* Default length of Rem. Node
X
X`009integer*4
X`0091`009JPI_Succ,`009`009!* GETJPI VMS Success Codes
X`0091`009Succ,`009`009`009!* VMS Success Code
X`0091`009Wild /-1/,`009`009!* Wildcard PID for GETJPI
X`0091`009PID`009`009`009!* PID
X
X`009integer*2
X`0091`009IOSB(4),`009`009!* I/O Status Block
X`0091`009P1_Username_Len,`009!* Length of Username to search for
X`0091`009Output_Filename_len,`009!* Output Filename length
X`0091`009Username_Len,`009`009!* Username length
X`0091`009PrcNam_Len,`009`009!* Process Name length
X`0091`009Terminal_Len,`009`009!* Terminal Name length
X`0091`009TT_PhyDevNam_Len,`009!* Physical Device Name length
X`0091`009Fmt_TT_PhyDevNam,`009!* Format length of Physical Device
X`0091`009Fmt_Remote_Node,`009!* Format length of Remote Node
X`0091`009Get_IJobCnt,`009`009!* Subroutine to retrieve SYS$GW_IJOBCNT
X`0091`009Line_Len,`009`009!* Length of Line
X`0091`009Chan,`009`009`009!* Channel to Terminal
X`0091`009User_Cnt /0/,`009`009!* Count of Users
X`0091`009KeyBuf(5) /`009`009!* Key Buffer for SOR Routines
X`0091`009    1,`009`009`009    !* Number of Keys
X`0091`009    DSC$K_DTYPE_T,`009    !* Type (Text)
X`0091`009    0,`009`009`009    !* Order (Ascending)
X`0091`009    1,`009`009`009    !* Offset (Byte 2)
X`0091`009    12/`009`009`009    !* Length (12 Bytes)
X
X`009volatile`009!* Don't Optimize these into Registers!
X`0091`009Username_Len,`009`009!* Username length
X`0091`009PrcNam_Len,`009`009!* Process Name length
X`0091`009Terminal_Len,`009`009!* Terminal Name length
X`0091`009TT_PhyDevNam_Len`009!* Physical Device Name length
X
X`009character
X`0091`009P1_Username*255,`009!* Username to search for
X`0091`009Output_Filename*255,`009!* Output File Name
X`0091`009Username*12,`009`009!* Username buffer
X`0091`009PrcNam*15,`009`009!* Process Name buffer
X`0091`009Terminal*7,`009`009!* Terminal Name buffer
X`0091`009TT_PhyDevNam*64,`009!* Physical Device Name of Terminal
X`0091`009Line*255`009`009!* Output line
X
X`009byte
X`0091`009Remote(34)`009`009!* Remote Node/Port
X
X`009logical*1
X`0091`009Get_Record,`009`009!* Get next record from sorted list
X`0091`009Full_Display`009`009!* Full Display?
X
X`009external
X`0091`009SYS$GW_IJOBCNT,`009`009!* In SYS$SYSTEM:SYS.STB
X`0091`009SHOW$_NOSUCHUSER`009!* In SYS$MESSAGE:CLIUTLMSG
X`009`009`009`009`009!* Pointer in SHWMSGPTR.OBJ
X
X!---------------------------------------------------------------------------
X!* Call CLI routines to parse the command line
X
X`009call Parse_Cmd_Line(
X`0091`009P1_Username,
X`0091`009P1_Username_Len,
X`0091`009Output_Filename,
X`0091`009Output_Filename_len,
X`0091`009Full_Display)
X
X!---------------------------------------------------------------------------
X!* Load the GETJPI and GETDVI Item Lists
X
X`009call Load_ItmLst(
X`0091`009GetJpi_ItmLst,
X`0091`009Username,
X`0091`009Username_Len,
X`0091`009PrcNam,
X`0091`009PrcNam_Len,
X`0091`009PID,
X`0091`009Terminal,
X`0091`009Terminal_Len,
X`0091`009GetDvi_ItmLst,
X`0091`009TT_PhyDevNam,
X`0091`009TT_PhyDevNam_Len)
X
X!---------------------------------------------------------------------------
X!* Initialization(s)
X
X`009Fmt_Remote_Node = DEF_REMOTE_NODE
X`009JPI_Succ = SS$_NORMAL`009!* Initialize JPI_Succ to successful
X
X!---------------------------------------------------------------------------
X!* Show Us More...
X
X`009!-------------------------------------------------------------------
X`009!* Repeat loop until no more processes
X
X`009do while ( (JPI_Succ) .or.`009`009`009!* Last GetJPI was Successful
X`0091`009   (JPI_Succ .eq. SS$_NOPRIV) .or.`009!* No privilege is ok
X`0091`009   (JPI_Succ .eq. SS$_SUSPENDED) )`009!* Suspended processes are ok
X
X`009    !---------------------------------------------------------------
X`009    !* GetJPI on the next process
X
X`009    JPI_Succ = SYS$GETJPIW(,Wild,,GetJpi_ItmLst,IOSB,,)
X`009    if (.not. JPI_Succ) goto 9999`009!* break
X`009    if (.not. IOSB(1)) call exit(IOSB(1))
X
X`009    !---------------------------------------------------------------
X`009    !* If no terminal then not an interactive user (break)
X
X`009    if (Terminal_Len .eq. 0) goto 9999`009!* break
X
X`009    !---------------------------------------------------------------
X`009    !* If user specified a username and it doesn't match then break
X
X`009    if (P1_Username_Len .ne. 0) then
V`009`009if (index(Username(1:Username_Len),P1_Username(1:P1_Username_Len)) .ne.
X 1) goto 9999`009!* break
X`009    endif
X
X`009    !---------------------------------------------------------------
X`009    !* Get the Physical Device name of the terminal
X
X`009    TT_PhyDevNam_Len = 0
X
X`009    Succ = SYS$GETDVIW(,,Terminal(1:Terminal_Len),GetDvi_ItmLst,IOSB,,,)
X`009    if (.not. Succ .and. Succ .ne. SS$_NOSUCHDEV) call exit(Succ)
X`009    if (.not. IOSB(1) .and. IOSB(1) .ne. SS$_NOSUCHDEV) call exit(IOSB(1))
X
X`009    Remote(1) = 0`009!* Initialize to null
X`009    Remote(2) = 0`009!* Initialize to null
X
X`009    if (TT_PhyDevNam_Len .eq. 0) then
X
X`009`009!-----------------------------------------------------------
X`009`009!* Physical device name is null so process is Disconnected
X
X`009`009TT_PhyDevNam = ' Disconnected'
X`009`009TT_PhyDevNam_Len = len(' Disconnected')
X`009`009Fmt_TT_PhyDevNam = TT_PhyDevNam_Len - 1
X
X`009    else
X
X`009`009Fmt_TT_PhyDevNam = DEF_TT_PhyDevNam
X
X`009`009!-----------------------------------------------------------
X`009`009!* Check if physical device name is a LAT device
X
X`009`009if (Succ .ne. SS$_NOSUCHDEV .and.
X`0091`009    index(Terminal(1:Terminal_Len),'LTA') .ne. 0 .or.
X`0091`009    index(TT_PhyDevNam(1:TT_PhyDevNam_Len),'LTA') .ne. 0) then
X
X`009`009    !-------------------------------------------------------
X`009`009    !* Assign a channel to the physical device
X
X`009`009    Succ = SYS$ASSIGN(TT_PhyDevNam(1:TT_PhyDevNam_Len),Chan,,)
X`009`009    if (Succ) then
X
X`009`009`009!---------------------------------------------------
X`009`009`009!* Get the Remote Port and Node name from the LTDRIVER
X
X`009`009`009Succ = SYS$QIOW(,%val(Chan),
X`0091`009`009    %val(IO$_TTY_PORT .or. IO$M_LT_READPORT),
X`0091`009`009    IOSB,,,Remote,%val(34),,,,)`009`009`009
X`009`009`009if (.not. Succ) call exit(Succ)
X`009`009`009if (.not. IOSB(1)) call exit(IOSB(1))
X
X`009`009`009!---------------------------------------------------
X`009`009`009!* Deassign the channel to the LAT device
X
X`009`009`009Succ = SYS$DASSGN(%val(Chan))
X`009`009`009if (.not. Succ) call exit(Succ)
X
X`009`009    else
X
X`009`009`009!---------------------------------------------------
X`009`009`009!* Channel assignment failed
X
X`009`009`009if (Succ .ne. SS$_NOSUCHDEV .and. Succ .ne. SS$_DEVALLOC)
X`0091`009`009    call exit(Succ)
X
X`009`009    endif`009!* successful assign call
X
X`009`009endif`009!* Terminal is a LAT device
X
X`009`009!-----------------------------------------------------------
X`009`009!* Physical Device name matches Terminal name so set to null
X
X`009`009if (index(TT_PhyDevNam(1:TT_PhyDevNam_Len),
X`0091`009    Terminal(1:Terminal_Len)) .ne. 0)
X`0091`009    TT_PhyDevNam_Len = 1
X
X`009    endif`009!* Pysical Device name checking
X`009`009
X`009    !---------------------------------------------------------------
X`009    !* User specified /FULL so set field lengths to full width
X
X`009    if (Full_Display) then
X`009`009Fmt_TT_PhyDevNam = max(DEF_TT_PhyDevNam,TT_PhyDevNam_Len-1)
X`009`009Fmt_Remote_Node = max(DEF_REMOTE_NODE,zext(Remote(Remote(1)+2)))
X`009    endif
X
X`009    !---------------------------------------------------------------
X`009    !* Format the output record
X
X`009    Succ = SYS$FAO(' !12AS !15AS !XL  !7AS !#AS !#AC !AC',
X`0091`009Line_Len, Line,
X`0091`009Username(1:Username_Len),
X`0091`009PrcNam(1:PrcNam_Len),
X`0091`009%val(PID),
X`0091`009Terminal(1:Terminal_Len),
X`0091`009%val(Fmt_TT_PhyDevNam),
X`0091`009TT_PhyDevNam(2:TT_PhyDevNam_Len),
X`0091`009%val(Fmt_Remote_Node),
X`0091`009Remote(Remote(1)+2),
X`0091`009Remote(1))
X`009    if (.not. Succ) call exit(Succ)
X
X`009    !---------------------------------------------------------------
X`009    !* Insert this record into the sorted list
X
-+-+-+-+-+ End of part 3 +-+-+-+-+-

