[rancid] Re: Maintainer hlogin , please review & comment .

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


  	Hello All ,

On Tue, 20 May 2008, Mr. James W. Laferriere wrote:
> 	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 .

 	An updated patch to try & shorten the path & make the checks a bit more 
portable for the varying hp devices .  please comment .

  	Again ,  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-21 09:30:25.000000000 -0800
@@ -473,13 +473,47 @@
     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 .
+# & Set the pageR off variable .
+proc chk_rtr {in_proc prompt timeout} {
+  log_user 0
+  set old_Timeout $timeout
+  set timeout 5
+  global pageR
+  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 pageR "no page"
+  }
+  if { $Buffer eq "Router" } {
+    # I'm a ROUTER ...
+    set pageR "terminal length 0"
+  }
+  if { $Buffer eq "." } {
+    # Default to (I think) I'm a ROUTER ... 
+    set pageR "terminal length 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 pageR } {
     global in_proc platform
     set in_proc 1
-
+    
     # Turn off the pager and escape regex meta characters in the $prompt
-    send "terminal length 0\r"
+    send "$pageR\r"
     regsub -all "\[)(]" $prompt {\\&} reprompt
     expect {
 	-re $reprompt	{}
@@ -717,13 +751,17 @@
 	-re "^.+$prompt"	{ set prompt $expect_out(0,string); }
     }
 
+    # check if we are on a route or not ,
+    # & Set pageR variable accordingly .  JimL
+    chk_rtr $in_proc $prompt $timeout
+
     if { $do_command } {
-	if {[run_commands $prompt $command]} {
+	if {[run_commands $prompt $command $pageR]} {
 	    continue
 	}
     } elseif { $do_script } {
 	# disable the pager
-	send "terminal length 0\r"
+        send "$pageR\r"
 	expect -re $prompt	{}
 	source $sfile
 	close


More information about the Rancid-discuss mailing list