! 10 Mar 89
! Name:		autoq.cmd
! Purpose:	Perform unattended reliable file transfers queued by q.cmd
! Usage:	"term autoq" or "term -q autoq" from UNIX cron
!

!
! Queuing directories:
!
switch
case opsys()=0		! VMS
	setvar qdir	"SYS\$SYSROOT:[TERM.QUEUE]"
case opsys()=1		! MSDOS
	setvar qdir	"/usr/term/queue/"
case opsys()=8		! BTOS
	setvar qdir	"[Sys]<Term>queue>"
case opsys()=9		! Mac
	setvar qdir	""
default			! UNIX-like systems
	setvar qdir	"/usr/term/queue/"	! queue dir
endswitch


setvar nodeext	".con"			! MUST be lowercase for compares
setvar qext	".*"
setvar wcard	"*"
setvar nodespec	"*"+nodeext
setvar qlog	"term.log"		! logfile name in qdir
setvar reqspec	qdir+qext


setvar maxnodes 22
dimstr nodes maxnodes


setvar cnt 0
for i in ($(qdir+wcard+nodeext)) do
	if cnt<maxnodes
		setvar nodes[cnt] left(i, len(i)-len(nodeext))
		setvar cnt cnt+1	! max out at maxnodes
	endif
endfor

! cnt now contains the actual number of nodes we might have to call

if cnt=0
	? "No systems defined for automatic file queuing process."
	? "Run 'term q' to define systems and queue transfer requests."
	quit
endif

on abort
	log "\^C operator abort"
	? "^C operator abort"
	logfile close
	return
endon

logfile $(qdir)$(qlog)
set log on			! auto logging

log "autoq startup"
setvar num 0
setvar anycalled FALSE
repeat
	setvar yesreq FALSE
	for i in ($(nodes[num]+qext)) do
		if tolower(right(i,len(nodeext)))!=nodeext
			setvar yesreq TRUE
		endif
	endfor
	if yesreq
		setvar anycalled TRUE
		do qproto $(nodes[num])
	endif
	setvar num num+1
until num=cnt
if not anycalled
	log "No transfers queued"
	? "No transfers queued"
endif

quit
