From:	RTPUX1::RTPUX1::"MCNC!CSD4.MILW.WISC.EDU!MOOCOW!BRODIE@RTPARK.GE.COM" 21-JUL-1989 20:40
To:	vmsnet@drycas.club.cc.cmu.edu
Subj:	LOGIN script for port selector w/queue

In Jamie's documentation for decus UUCP (vmsnet), he requests that
anyone send "interesting" login scripts.  Well, I think the one below
qualifies.  (I tried the double-expect thing, and it works dandy!)
[thanks, jamie!]
 
One of the systems I call on a regular basis has a standard port
selector (they have many machines), but during the day I discovered
that there is also a port QUEUE, when things get really busy.   I was
discovering that my mail/news was sitting around ALL day, which sort
of delays things a bit.  ("i HATE it when that happens...")
 
Anyway, the script I've included below works just great.  Be forwarned
that uucico_callout.log can get pretty big depending on how many times
you "wait" in the queue.  (TONS of 'tick' messages).
 
I don't think I have to describe this any further--  the comments 
say it all.
----------------cut here------------------------------------------
! special script for "uwmcsd4", have to go through a port selector.
! also included is the ability to wait in the port selector queue.
! (C) 1989 Kent C. Brodie - Medical College of Wisconsin
! P0 is systemname , P1 is username, P2 is password. 
 
	zero
 
! send a CR to get the selector's attention.  Sleep a little bit
! due to large login text of selector.   It sends "Which System?"
! when it's ready. 
 
getprtslct:
	count
	ifgtr	noprtslct	6
	break
	send	\r
	sleep	2000
	flush
	expect	prtslctok	ystem?
	timeout	getprtslct	15000
 
noprtslct:
	logerr	Sent cr, no "Which System?" from port selector
	failed
 
! Send the system name.  We either get "OK" (connected), or we
! get "No ports available, would you like to wait?" (wait in queue)
 
prtslctok:
	zero
	sendstr	0
	send	\r
	expect	connected	OK
	expect	prtslctwait	wait?
	timeout	noconnect	10000
 
! Usually we get "nn Your place in queue" messages.  JUST in case we
! get a free port right away, check for 'Are you ready?' as well.
 
prtslctwait:
	zero
	send	Y
	send	\r
	expect	prtslctque	queue
	expect	prtslctrdy	ready?
	timeout	prtwaitbad	70000
 
prtwaitbad:
	logerr	Sent "Y" to wait in queue, did not get valid response.
	failed
 
! Here's where we wait in the queue.  The port selector sends us a status
! message about once a minute.  We either get "nn Your place in queue"
! or we get "System Available.  Are you Ready?". 
! If something goes wrong, we time out waiting for either response.
! The reason we don't sleep for 40-50 seconds is because as SOON as the
! port is ready, it informs us.  If we wait too long, it drops us.
! This setup is layed out for a maximum of 20 "tries" which is ABOUT
! 20 minutes.   Note:  This constant retrying can make log files
! kind of big....
 
prtslctque:
	count
	ifgtr	prtslcttry	20
	expect	prtslctque	queue
	expect	prtslctrdy	ready?
	timeout	noportwait	70000
 
prtslcttry:
	logerr	Too many (20) wait/retries -- queue too busy.
	failed
 
prtslctrdy:
	send	Y
	send	\r
	expect	connected	OK
	timeout	noconnect	20000
 
 
noportwait:
	logerr  Timed out awaiting place in port queue
	failed
 
noconnect:
	logerr	Sent system name, no "OK" from selector
	failed
 
! standard Unix login stuff.  Send cr, expect "ogin:", if no, send a break 
! (which tells Unix to try the next bit rate) and try again.  
 
connected:
	send	\r
	zero
	goto	waitlogin
 
sendbreak:
	count
	ifgtr	nolgi		6
	flush
	break
 
waitlogin:
	expect	gotlogin	ogin:
	timeout	sendbreak	5000
 
nolgi:
	logerr	No login: prompt
	failed
 
gotlogin:
	sendstr	1
	send	\r
	expect	gotword		word:
	timeout	nopwd		10000
 
nopwd:
	logerr	No password: prompt
	failed
 
gotword:
	sendstr	2
	send	\r
	success
----------------------cut here-------------------------------------
Kent C. Brodie	Systems Manager at Large - Medical College of WI
UUCP:		{uunet!marque,csd4.milw.wisc.edu}!moocow!brodie  
MA BELL:	+1 414 778-4056 (or 414-257-8769)    
"filling a PEZ dispenser - it's not just a skill, it's an ART."
 
