[rancid] Re: jlogin and root shell

Ernest Johanson johanson at caltech.edu
Fri May 7 16:41:10 UTC 2010


Dale,

I have a Juniper EX4200 that doesn't automatically launch the cli. The 
following worked for me. I also had to set TERM=xterm in rancid.conf.

--Ernie Johanson

--- jlogin.orig	2010-05-07 09:29:37.000000000 -0700
+++ jlogin	2010-05-07 09:29:37.000000000 -0700
@@ -285,7 +285,7 @@
  # Log into the router.
  # returns: 0 on success, 1 on failure
  proc login { router user passwd cmethod cyphertype identfile} {
-    global spawn_id in_proc do_command do_script passphrase prompt
+    global spawn_id in_proc do_command do_script passphrase prompt 
sys_prompt
      global sshcmd
      set in_proc 1

@@ -405,7 +405,13 @@
  						  sleep 1; send 
"$passwd\r"
  						  exp_continue
  						}
-	    -re "$prompt"		{ break; }
+	    # We define an additional prompt if the switch doesn't
+	    # start the cli by default
+	    -re "$sys_prompt"		{ break; }
+
+	    # Standard cli prompt
+	    -re "$prompt"           { break; }
+
  	    denied	{ send_user "\nError: Check your password for 
$router\n"
  	                  catch {close}; catch {wait}; return 1
  	                }
@@ -416,7 +422,14 @@
      send "\r"
      expect {
  	-re "(\r\n|\n)"		{ exp_continue; }
-	-re "^\[^ ]+$prompt"	{ set prompt $expect_out(0,string);
+
+	# If we get the system prompt, launch the cli
+
+	-re ".+$sys_prompt"	{ sleep 1; send "cli\r";
+				  exp_continue;
+				}
+	-re ".+$prompt"
+				{ set prompt $expect_out(0,string);
  				  regsub ">" $prompt "\[#>]" prompt;
  				}
      }
@@ -427,7 +440,7 @@

  # Run commands given on the command line.
  proc run_commands { prompt command } {
-    global in_proc
+    global in_proc sys_prompt
      set in_proc 1

      send "set cli complete-on-space off\r"
@@ -458,6 +471,11 @@
      }
      send "quit\r"
      expect {
+	-re ".+$sys_prompt"			{
+						  sleep 1 ; send "exit\r" 
;
+						  catch {close}; catch 
{wait};
+						  return 0
+						}
  	"\n"					{ exp_continue }
  	timeout					{ catch {close}; catch 
{wait};
  						  return 0
@@ -479,6 +497,11 @@

      set prompt ">"

+    # If the switch doesn't automatically
+    # launch the cli, we'll get a system prompt
+
+    set sys_prompt "%"
+
      # Figure out username
      if {[info exists username]} {
        # command line username

#--------------------- end diff -----------------------------------------

On Fri, 7 May 2010, Dale Shaw wrote:

> Date: Fri, 7 May 2010 08:25:47 +1000
> From: Dale Shaw <dale.shaw+rancid-discuss at gmail.com>
> To: rancid-discuss at shrubbery.net
> Subject: [rancid] jlogin and root shell
> 
> Hi all,
>
> [ I admit to not having done a thorough search through the archives on
> this one -- apologies if the answer is out there already, or -gulp-
> it's a FAQ ]
>
> Can jlogin handle the situation where the 'root' user is used to
> authenticate and is subsequently dropped into a shell, as distinct
> from the JUNOS CLI?
>
> cheers,
> Dale
> _______________________________________________
> Rancid-discuss mailing list
> Rancid-discuss at shrubbery.net
> http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
>


More information about the Rancid-discuss mailing list