! LOGIN.DECSERVER_VMS
! From Todd Aven (manager@usgcdh)

! P0 = host, P1 = username, P2 = password, p3 = optional system password.  

	zero
	sleep	2000			! wait two seconds

get_local:
	count
	ifgtr	no_local	5	! Die if 5 CRs don't do it
	send			\r
	expect	got_local	>
	timeout	get_local	500	! wait half-sec and try again

got_local:
	zero
	send			SET PORT OUT FLOW DIS INPUT FLOW DIS\r
	send			CONNECT\s
	sendstr	0			! send the name of the node
	send			\r
	ifnstr	abd_nospw	3	! jump if no spw provided

abd_spw:
	count
	ifgtr	gotbell		9	! if tried 9 times, assume missed bell
	send			\r
	expect	gotbell		\007
	expect	gotunp		Username:
	timeout	abd_spw		2000	! wait two secs and try again

gotbell:
	zero
	sleep	2000
sendspw:
	count
	ifgtr	nounp		9
	sendstr	3			! send the system password
	send	\r
	expect	gotunp		Username:
	timeout	sendspw		2000

abd_nospw:
	count
	ifgtr	nounp		9	! if tried 9 times, give up
	send			\r
	expect	gotunp		Username:
	timeout	abd_nospw	2000	! wait two secs and try again

no_local:
	logerr	didn't see Local> prompt
	failed

nounp:
	logerr	didn't see Username prompt
	failed

gotunp:
	sendstr	1
	send	\r
	ifnstr	done		2

! note that we need not wait for a password prompt, 
! we can just shove it into the typeahead buffer. 

	sendstr	2
	send	\r
done:
	log	VMS login ok
	success

