--- /usr/libexec/rancid/clogin	2019-02-06 02:03:27.000000000 -0500
+++ /usr/local/libexec/rancid/bslogin	2019-02-20 15:40:04.747945375 -0500
@@ -1,7 +1,5 @@
 #! /usr/bin/expect --
 ##
-## $Id: clogin.in 3943 2019-01-18 16:18:34Z heas $
-##
 ## rancid 3.9
 ## Copyright (c) 1997-2018 by Henry Kilmer and John Heasley
 ## All rights reserved.
@@ -46,7 +44,8 @@
 #  The original looking glass software was written by Ed Kern, provided by
 #  permission and modified beyond recognition.
 #
-# clogin - Cisco login
+# bslogin - Bay Networks/Nortel/Avaya BayStack/BPS/ERS login script
+#	    Supports models BPS 2000, 470, ERS 25xx/45xx/55xx/56xx.
 #
 # Most options are intuitive for logging into a Cisco router.
 # The default is to enable (thus -noenable).  Some folks have
@@ -646,6 +645,23 @@
 	-re "Press the <tab> key \[^\r\n]+\[\r\n]+"	{
 				  exp_continue
 				}
+	-re "##+"	        {
+				  # BayStacks have a default banner that spells out NORTEL or AVAYA in huge
+				  # letters made from ## that look like prompt characters, so we need to skip
+				  # over them.
+				  exp_continue
+				}
+	-re "Enter Ctrl-Y to begin" {
+				  # After the default or custom banner, BayStacks prompt for Ctrl-Y and
+				  # then display a static banner with model and version info surrounded
+	                          # by an asterisk border.  Discard the top and bottom of the border and
+	                          # send a Ctrl-Y and remember that this is a baystack for logout procedure.
+				  set platform "baystack"
+				  expect -ex "***************************************************************" {}
+				  expect -ex "***************************************************************" {}
+				  send "\031"
+				  exp_continue
+			      }
 	-re "@\[^\r\n]+ $p_prompt"	{
 				  # ssh pwd prompt
 				  sleep 1
@@ -803,10 +819,16 @@
 	return 0
     }
 
-    if { [string compare "extreme" "$platform"] } {
-	send -h "exit\r"
-    } else {
+    if { ![string compare "extreme" "$platform"] } {
 	send -h "quit\r"
+    } elseif { ![string compare "baystack" "$platform"] } {
+	# BayStacks use logout to completely exit, but they
+	# can also exit back to a menu interface, so send L
+	# to logout from the menu too just in case.
+	send -- "logout\r"
+	send -- "L"
+    } else {
+	send -h "exit\r"
     }
     expect {
 	-re "^\[^\n\r *]*$reprompt"		{
@@ -1058,7 +1080,15 @@
 				}
     }
     if { $do_command || $do_script } {
-	if { [string compare "extreme" "$platform"] } {
+	if { ![string compare "extreme" "$platform"] } {
+	    send "disable clipaging\r"
+	    expect -re $prompt		{}
+	} elseif { ![string compare "baystack" "$platform"] } {
+	    send -- "terminal length 0\r"
+	    expect -re $prompt		{}
+	    send -- "terminal width 131\r"
+	    expect -re $prompt		{}
+	} else {
 	    # If the prompt is (enable), then we are on a cataylyst switch and
 	    # the command is "set length 0"; otherwise its "terminal length 0".
 	    if [regexp -- ".*> .*enable" "$prompt"] {
@@ -1073,9 +1103,6 @@
 		send "terminal width 132\r"
 	    }
 	    expect -re $prompt		{}
-	} else {
-	    send "disable clipaging\r"
-	    expect -re $prompt		{}
 	}
     }
     if { $do_command } {
