From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM"  7-SEP-1993 08:31:56.67
To:	EVERHART
CC:	
Subj:	Summary: Log file protection

From: webosk@itwol.bhp.com.au (Ken Bosward)
X-Newsgroups: comp.os.vms
Subject: Summary: Log file protection
Message-Id: <1993Sep6.092447.48@iwsd01.itwol.bhp.com.au>
Date: 6 Sep 93 09:24:47 +1000
Organization: BHP Information Technology
Lines: 66
To: Info-VAX@kl.sri.com
X-Gateway-Source-Info: USENET

Thanks to all who responded to my question about whether it is possible
to get the name of the log file from within the executing batch job (and
therefore to set the protection on the file as soon as the job starts
executing, to give world read access).

In summary, using documented means, it is possible to get the log file
*specification* from within the command procedure (see example below),
but not necessarily the correct version number of the log file. The
method will fail if two jobs executing simultaneously have the same log
file name in the same directory -- in this case the method will always
return the log file with the highest version number (which may or may
not be the log file for the currently executing job!).

It is also possible to get the File Identifier (and therefore the exact
file name, including version number, using LIB$FID_TO_NAME) of the log
file, using undocumented (= may break at any time) means (see second
example below).

---------------------------cut here-------------------------------------
$! GET_LOG_FILE_NAME.COM
$! Get the log file name for the batch job which calls this procedure.
$! If there is no log file, return a null string.
$!
$! NOTE: IF ANOTHER BATCH JOB IS EXECUTING AND HAS A LOG FILE WITH THE
$! SAME NAME IN THE SAME DIRECTORY, THIS PROCEDURE CANNOT DETERMINE
$! WHICH LOG FILE BELONGS TO WHICH JOB. IT WILL ALWAYS RETURN THE
$! SPECIFICATION OF THE LOG FILE WITH THE HIGHEST VERSION NUMBER.
$!
$! @GET_LOG_FILE_NAME <symbol-name>
$!   where <symbol-name> is the name of a global symbol to receive the
$!   log file name.
$!
$ symbol_name = p1
$ if symbol_name .eqs. "" then exit %x00038048  ! CLI$_INSFPRM
$ 'symbol_name' == ""
$! Exit if not batch mode
$ if f$mode() .nes. "BATCH" then exit
$! Check flag bit QUI$V_JOB_LOG_NULL (no log file)
$ job_flags = f$getqui("DISPLAY_JOB", "JOB_FLAGS",, "THIS_JOB")
$ if (job_flags .and. %x00000800) .ne. 0 then exit
$ log_spec = f$getqui("DISPLAY_JOB", "LOG_SPECIFICATION",, "THIS_JOB")
$ job_name = f$getqui("DISPLAY_JOB", "JOB_NAME",, "THIS_JOB")
$ 'symbol_name' == f$parse(log_spec, job_name, "SYS$LOGIN:.LOG;")
---------------------------cut here-------------------------------------
$! SHOW_OUTDEV.COM
$! Show output device FID and DVI.
$!
$! NOTE: THIS CODE MAY NOT WORK IF THE VMS VERSION CHANGES (CURRENTLY
$! WORKS FOR VAX VMS V5.4).
$!
$ PPD$C_LENGTH = 360            ! From SYS$SYSTEM:DCLDEF.STB
$ PPD$T_OUTDVI = 72             !
$ PPD$W_OUTFID = 88             !
$ CTL$AG_CLIDATA = %x7FFE2A5C   ! From SYS$SYSTEM:SYS.STB
$!
$ wo := write sys$output
$ ppd = f$fao("!AD", PPD$C_LENGTH, CTL$AG_CLIDATA)
$ wo "OUTDVI: ", f$extract(PPD$T_OUTDVI+1, -
                 f$cvui(PPD$T_OUTDVI*8, 8, ppd), ppd)
$ wo "OUTFID: (", f$cvui(PPD$W_OUTFID*8, 16, ppd), -
             ",", f$cvui(PPD$W_OUTFID*8+16, 16, ppd), -
             ",", f$cvui(PPD$W_OUTFID*8+32, 16, ppd), ")"
$ exit
-- 
Ken Bosward, BHP Information Technology, Wollongong. Australia.
E-mail: webosk@itwol.bhp.com.au

