[rancid] Maintainer hlogin , please review & comment .

Mr. James W. Laferriere babydr at baby-dragons.com
Wed May 21 00:00:09 UTC 2008


 	Hello (whomever, tho probaby) JohnH ,
 	I've made an attempt to check between switch & routers of the procurve 
persuasion with this patch to this script .
 	There are probably better ways of doing this than I have implemented , 
Please comment with code (even pseudeo) .
 	Find it attached to prevent mailer mangle .

 		Tia ,  JimL
-- 
+------------------------------------------------------------------+
| James   W.   Laferriere | System    Techniques | Give me VMS     |
| Network&System Engineer | 2133    McCullam Ave |  Give me Linux  |
| babydr at baby-dragons.com | Fairbanks, AK. 99701 |   only  on  AXP |
+------------------------------------------------------------------+
-------------- next part --------------
--- /usr/local/rancid/bin/hlogin-v1_40-20061208	2008-05-15 17:00:00.000000000 -0800
+++ /usr/local/rancid/bin/hlogin	2008-05-20 15:37:58.000000000 -0800
@@ -473,13 +473,52 @@
     return 0
 }
 
+# Check (as best we can) if we are on a HP router or switch .
+# Actually checking if is a router & saying otherwise it's a switch .
+#
+proc chk_rtr {in_proc prompt timeout} {
+  log_user 0
+  set old_Timeout $timeout
+  set timeout 5
+  global chk_rtrR
+  exp_send "show version\r"
+  expect {
+    -re "Image stamp" {
+      set Buffer $expect_out(0,string); 
+    }
+    -re "Router" {
+      set Buffer $expect_out(0,string); 
+    }
+  }
+  if { $Buffer eq "Image stamp" } {
+    # I'm a SWITCH ...
+    set chk_rtrR 1
+  }
+  if { $Buffer eq "Router" } {
+    # I'm a ROUTER ...
+    set chk_rtrR 0
+  }
+  if { $Buffer eq "" } {
+    # Default to (I think) I'm a ROUTER ... 
+    set chk_rtrR 0
+  }
+  set timeout $old_Timeout
+  log_user 1
+  return
+}
+
 # Run commands given on the command line.
-proc run_commands { prompt command } {
+proc run_commands { prompt command chk_rtrR } {
     global in_proc platform
     set in_proc 1
-
+    
+    # see if we're a router or not and then ...
     # Turn off the pager and escape regex meta characters in the $prompt
-    send "terminal length 0\r"
+    if { $chk_rtrR == 0 } {
+        send "terminal length 0\r"
+    } else {
+        send "no page\r"
+    }
     regsub -all "\[)(]" $prompt {\\&} reprompt
     expect {
 	-re $reprompt	{}
@@ -717,13 +756,21 @@
 	-re "^.+$prompt"	{ set prompt $expect_out(0,string); }
     }
 
+    # check if we are on a route or not .  JimL
+    chk_rtr $in_proc $prompt $timeout
+
     if { $do_command } {
-	if {[run_commands $prompt $command]} {
+	if {[run_commands $prompt $command $chk_rtrR]} {
 	    continue
 	}
     } elseif { $do_script } {
+	# see if we're a router or not and then ...
 	# disable the pager
-	send "terminal length 0\r"
+	if { $chk_rtrR == 0 } {
+            send "terminal length 0\r"
+        } else {
+            send "no page\r"
+        }
 	expect -re $prompt	{}
 	source $sfile
 	close


More information about the Rancid-discuss mailing list