diff options
author | Tar Committer <tar@ocjtech.us> | 2001-08-03 03:13:25 +0000 |
---|---|---|
committer | Tar Committer <tar@ocjtech.us> | 2001-08-03 03:13:25 +0000 |
commit | af496d2efa0969f29a22a4236c620f513eb90287 (patch) | |
tree | f3bc37d0d677b7ae1b58ae643fa25a91b80655aa /bin/alogin.in | |
parent | 0e84b727786a16ade28bb081742e5c39c33ed7fa (diff) | |
download | rancid-af496d2efa0969f29a22a4236c620f513eb90287.tar.gz rancid-af496d2efa0969f29a22a4236c620f513eb90287.tar.xz rancid-af496d2efa0969f29a22a4236c620f513eb90287.zip |
Imported from rancid-2.2b5.tar.gz.rancid-2.2b5
Diffstat (limited to 'bin/alogin.in')
-rwxr-xr-x | bin/alogin.in | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/bin/alogin.in b/bin/alogin.in index fe55787..8ccf37b 100755 --- a/bin/alogin.in +++ b/bin/alogin.in @@ -1,7 +1,7 @@ #!@EXPECT_PATH@ -- ## ## -## Copyright (C) 1997 by Henry Kilmer, Erik Sherk and Pete Whiting. +## Copyright (C) 1997-2001 by Henry Kilmer, Erik Sherk and Pete Whiting. ## All rights reserved. ## ## This software may be freely copied, modified and redistributed without @@ -23,10 +23,10 @@ # # Usage line -set usage "Usage: $argv0 \[-c command\]\ -\[-f cloginrc-file\]\ -\[-s script-file\] \[-t timeout\] \[-u username\]\ -\[-v vty-password\] \[-x command-file\]\ +set usage "Usage: $argv0 \[-c command\] \ +\[-Evar=x\] \[-f cloginrc-file\] \ +\[-s script-file\] \[-t timeout\] \[-u username\] \ +\[-v vty-password\] \[-x command-file\] \ \[-y ssh_cypher_type\] router \[router...\]\n" # env(CLOGIN) may contain: @@ -88,9 +88,19 @@ for {set i 0} {$i < $argc} {incr i} { } -w* - -W* { # ignore -w + # Environment variable to pass to -s scripts + } -E* + { + if {[ regexp .\[E\](.+)=(.+) $arg ignore varname varvalue]} { + incr i + set E$varname $varvalue + } else { + send_user "Error: invalid format for -E in $arg\n" + exit 1 + } # Enable Password - } -e* - - -E* { + } -e* + { # ignore -e # Command to run. } -c* - @@ -140,7 +150,10 @@ for {set i 0} {$i < $argc} {incr i} { incr i set cmd_file [ lindex $argv $i ] } - set cmd_fd [open $cmd_file r] + if [ catch {set cmd_fd [open $cmd_file r]} reason ] { + send_user "\nError: $reason\n" + exit 1 + } set cmd_text [read $cmd_fd] close $cmd_fd set command [join [split $cmd_text \n] \;] @@ -320,7 +333,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } { catch {close}; wait; return 1 } eof { send_user "Error: Couldn't login\n"; wait; return 1 } -re "$p_prompt" { send "$userpswd\r" } - "$prompt" { set in_proc 0; return 0 } + -re "$prompt" { set in_proc 0; return 0 } } exp_continue } @@ -329,7 +342,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } { "Password incorrect" { send_user "Error: Couldn't login\n"; catch {close}; wait; return 1 } eof { send_user "Error: Couldn't login\n"; wait; return 1 } - "$prompt" { set in_proc 0; return 0 } + -re "$prompt" { set in_proc 0; return 0 } "Confirm seeing above note" { send "y\r" } } exp_continue @@ -337,7 +350,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } { -re "^Confirm seeing above note" { send "y\r" } "Password incorrect" { send_user "Error: Check your password for $router\n"; catch {close}; wait; return 1 } - "$prompt" { } + -re "$prompt" { } denied { send_user "Error: Check your passwd for $router\n" if { $do_command || $do_script } { send "exit\r" @@ -347,7 +360,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } { return 1 } } - "\r\n" { exp_continue; } + "\r\n" { exp_continue; } } set in_proc 0 return 0 @@ -360,7 +373,7 @@ proc run_commands { prompt command } { set in_proc 1 send "lines 0\r" - expect $prompt {} + expect -re $prompt {} regsub -all "\[)(]" $prompt {\\&} reprompt @@ -368,21 +381,20 @@ proc run_commands { prompt command } { if [ string match "*\;*" "$command" ] { set commands [split $command \;] set num_commands [llength $commands] - for {set i 0} {$i < $num_commands} { incr i} { send "[subst -nocommands [lindex $commands $i]]\r" expect { - -re "^\[^\n\r]*$reprompt." {} + -re "^\[^\n\r]*$reprompt" {} -re "^\[^\n\r ]*>>.*$reprompt" { exp_continue } - -re "\[\n\r]" { exp_continue } + -re "\[\n\r]+" { exp_continue } } } } else { send "[subst -nocommands $command]\r" expect { - -re "^\[^\n\r]*$reprompt." {} + -re "^\[^\n\r]*$reprompt" {} -re "^\[^\n\r ]*>>.*$reprompt" { exp_continue } - -re "\[\n\r]" { exp_continue } + -re "\[\n\r]+" { exp_continue } } } send "exit\r" @@ -410,9 +422,10 @@ foreach router [lrange $argv $i end] { send_user "$router\n" # Figure out prompt. - set prompt "#" - set autoenable 1 - set enable 0 + set prompt ">> \[^\r\n]*\[#|>] " + # alteon only "enables" based on the password used at login time + set autoenable 1 + set enable 0 # Figure out passwords if { $do_passwd } { @@ -472,7 +485,7 @@ foreach router [lrange $argv $i end] { } } elseif { $do_script } { send "lines 0\r" - expect $prompt {} + expect -re $prompt {} source $sfile close } else { |