summaryrefslogtreecommitdiffstats
path: root/bin/clogin.in
diff options
context:
space:
mode:
Diffstat (limited to 'bin/clogin.in')
-rw-r--r--bin/clogin.in29
1 files changed, 18 insertions, 11 deletions
diff --git a/bin/clogin.in b/bin/clogin.in
index 92bb2f8..d4f27db 100644
--- a/bin/clogin.in
+++ b/bin/clogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: clogin.in,v 1.79 2004/05/27 21:57:52 heas Exp $
+## $Id: clogin.in,v 1.85 2005/06/14 20:20:43 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -59,7 +59,7 @@ set do_enapasswd 1
set platform ""
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -286,6 +286,7 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
global spawn_id in_proc do_command do_script platform
global prompt u_prompt p_prompt e_prompt sshcmd
@@ -295,6 +296,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
@@ -304,7 +306,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
}
} elseif [string match "ssh*" $prog] {
regexp {ssh(:([^[:space:]]+))*} $prog command suffix port
@@ -316,18 +318,23 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
}
if { $retval } {
send_user "\nError: $sshcmd failed: $reason\n"
- exit 1
+ return 1
}
} elseif ![string compare $prog "rsh"] {
+ if { ! $do_command } {
+ if { $progs == 0 } {
+ return 1
+ }
+ continue;
+ }
if [ catch {spawn rsh -l $user $router} reason ] {
send_user "\nError: rsh failed: $reason\n"
- exit 1
+ return 1
}
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
# This helps cleanup each expect clause.
@@ -617,10 +624,10 @@ foreach router [lrange $argv $i end] {
set router [string tolower $router]
send_user "$router\n"
- # Figure out prompt.
- # Since autoenable is off by default, if we have it defined, it
- # was done on the command line. If it is not specifically set on the
- # command line, check the password file.
+ # Figure out the prompt.
+ # autoenable is off by default. If we have it defined, it was done
+ # on the command line. If it is not specifically set on the command
+ # line, check the password file.
if $avautoenable {
set autoenable 1
set enable 0