Advertisement
Guest User

bnlogin

a guest
Oct 22nd, 2013
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 22.15 KB | None | 0 0
  1. #! /usr/bin/expect --
  2. ##
  3. ## $Id: blogin.in,v 1.50 2009/04/16 21:22:57 heas Exp $
  4. ##
  5. ## @PACKAGE@ @VERSION@
  6. ## Copyright (c) 1997-2009 by Terrapin Communications, Inc.
  7. ## All rights reserved.
  8. ##
  9. ## This code is derived from software contributed to and maintained by
  10. ## Terrapin Communications, Inc. by Henry Kilmer, John Heasley, Andrew Partan,
  11. ## Pete Whiting, Austin Schutz, and Andrew Fort.
  12. ##
  13. ## Redistribution and use in source and binary forms, with or without
  14. ## modification, are permitted provided that the following conditions
  15. ## are met:
  16. ## 1. Redistributions of source code must retain the above copyright
  17. ##    notice, this list of conditions and the following disclaimer.
  18. ## 2. Redistributions in binary form must reproduce the above copyright
  19. ##    notice, this list of conditions and the following disclaimer in the
  20. ##    documentation and/or other materials provided with the distribution.
  21. ## 3. All advertising materials mentioning features or use of this software
  22. ##    must display the following acknowledgement:
  23. ##        This product includes software developed by Terrapin Communications,
  24. ##        Inc. and its contributors for RANCID.
  25. ## 4. Neither the name of Terrapin Communications, Inc. nor the names of its
  26. ##    contributors may be used to endorse or promote products derived from
  27. ##    this software without specific prior written permission.
  28. ## 5. It is requested that non-binding fixes and modifications be contributed
  29. ##    back to Terrapin Communications, Inc.
  30. ##
  31. ## THIS SOFTWARE IS PROVIDED BY Terrapin Communications, INC. AND CONTRIBUTORS
  32. ## ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  33. ## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34. ## PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COMPANY OR CONTRIBUTORS
  35. ## BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  36. ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  37. ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  38. ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  39. ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. ## POSSIBILITY OF SUCH DAMAGE.
  42. #
  43. #  The expect login scripts were based on Erik Sherk's gwtn, by permission.
  44. #
  45. # blogin - Bay Networks(Nortel) login
  46. #
  47. # Unlike the Cisco's, there is no enable function on the Bay's.  Instead
  48. # there are seperate User and Manager accounts.  A 'system' command exists,
  49. # which I am told does nothing.
  50. #
  51. # The "bcc>" prompt changes to "box#", not "bcc#" after the config command.
  52. #
  53.  
  54. # Usage line
  55. set usage "Usage: $argv0 \[-dSV\] \[-autoenable\] \[-noenable\] \[-c command\] \
  56. \[-Evar=x\] \[-e enable-password\] \[-f cloginrc-file\] \[-p user-password\] \
  57. \[-s script-file\] \[-t timeout\] \[-u username\] \
  58. \[-v vty-password\] \[-w enable-username\] \[-x command-file\] \
  59. \[-y ssh_cypher_type\] router \[router...\]\n"
  60.  
  61. # env(CLOGIN) may contain:
  62. #       x == do not set xterm banner or name
  63.  
  64. # Password file
  65. set password_file $env(HOME)/.cloginrc
  66. # Default is to login to the router
  67. set do_command 0
  68. set do_script 0
  69. # The default is to automatically enable
  70. set avenable 0
  71. # The default is that you login non-enabled (tacacs can have you login already
  72. # enabled)
  73. set avautoenable 0
  74. # The default is to look in the password file to find the passwords.  This
  75. # tracks if we receive them on the command line.
  76. set do_passwd 1
  77. set do_enapasswd 0
  78. # Save config, if prompted
  79. set do_saveconfig 0
  80.  
  81. # Find the user in the ENV, or use the unix userid.
  82. if {[ info exists env(CISCO_USER) ]} {
  83.     set default_user $env(CISCO_USER)
  84. } elseif {[ info exists env(USER) ]} {
  85.     set default_user $env(USER)
  86. } elseif {[ info exists env(LOGNAME) ]} {
  87.     set default_user $env(LOGNAME)
  88. } else {
  89.     # This uses "id" which I think is portable.  At least it has existed
  90.     # (without options) on all machines/OSes I've been on recently -
  91.     # unlike whoami or id -nu.
  92.     if [ catch {exec id} reason ] {
  93.         send_error "\nError: could not exec id: $reason\n"
  94.         exit 1
  95.     }
  96.     regexp {\(([^)]*)} "$reason" junk default_user
  97. }
  98. if {[ info exists env(CLOGINRC) ]} {
  99.     set password_file $env(CLOGINRC)
  100. }
  101.  
  102. # Sometimes routers take awhile to answer (the default is 10 sec)
  103. set timeout 45
  104.  
  105. # Process the command line
  106. for {set i 0} {$i < $argc} {incr i} {
  107.     set arg [lindex $argv $i]
  108.  
  109.     switch  -glob -- $arg {
  110.         # Expect debug mode
  111.         -d* {
  112.             exp_internal 1
  113.         # Username
  114.         } -u* {
  115.             if {! [  regexp .\[uU\](.+) $arg ignore user]} {
  116.                 incr i
  117.                 set username [ lindex $argv $i ]
  118.             }
  119.         # VTY Password
  120.         } -p* {
  121.             if {! [  regexp .\[pP\](.+) $arg ignore userpasswd]} {
  122.                 incr i
  123.                 set userpasswd [ lindex $argv $i ]
  124.             }
  125.             set do_passwd 0
  126.         # VTY Password
  127.         } -v* {
  128.             if {! [  regexp .\[vV\](.+) $arg ignore passwd]} {
  129.                 incr i
  130.                 set passwd [ lindex $argv $i ]
  131.             }
  132.             set do_passwd 0
  133.         # Version string
  134.         } -V* {
  135.             send_user "@PACKAGE@ @VERSION@\n"
  136.             exit 0
  137.         # Enable Username
  138.         } -w* {
  139.             if {! [  regexp .\[wW\](.+) $arg ignore enauser]} {
  140.                 incr i
  141.                 set enausername [ lindex $argv $i ]
  142.             }
  143.         # Environment variable to pass to -s scripts
  144.         } -E* {
  145.             if {[ regexp .\[E\](.+)=(.+) $arg ignore varname varvalue]} {
  146.                 set E$varname $varvalue
  147.             } else {
  148.                 send_user "\nError: invalid format for -E in $arg\n"
  149.                 exit 1
  150.             }
  151.         # Enable Password
  152.         } -e* {
  153.             if {! [  regexp .\[eE\](.+) $arg ignore enapasswd]} {
  154.                 incr i
  155.                 set enapasswd [ lindex $argv $i ]
  156.             }
  157.             set do_enapasswd 0
  158.         # Command to run.
  159.         } -c* {
  160.             if {! [  regexp .\[cC\](.+) $arg ignore command]} {
  161.                 incr i
  162.                 set command [ lindex $argv $i ]
  163.             }
  164.             set do_command 1
  165.         # Expect script to run.
  166.         } -s* {
  167.             if {! [  regexp .\[sS\](.+) $arg ignore sfile]} {
  168.                 incr i
  169.                 set sfile [ lindex $argv $i ]
  170.             }
  171.             if { ! [ file readable $sfile ] } {
  172.                 send_user "\nError: Can't read $sfile\n"
  173.                 exit 1
  174.             }
  175.             set do_script 1
  176.         # save config on exit
  177.         } -S* {
  178.             set do_saveconfig 1
  179.         # 'ssh -c' cypher type
  180.         } -y* {
  181.             if {! [  regexp .\[eE\](.+) $arg ignore cypher]} {
  182.                 incr i
  183.                 set cypher [ lindex $argv $i ]
  184.             }
  185.         # alternate cloginrc file
  186.         } -f* {
  187.             if {! [ regexp .\[fF\](.+) $arg ignore password_file]} {
  188.                 incr i
  189.                 set password_file [ lindex $argv $i ]
  190.             }
  191.         # Timeout
  192.         } -t* {
  193.             if {! [ regexp .\[tT\](.+) $arg ignore timeout]} {
  194.                 incr i
  195.                 set timeout [ lindex $argv $i ]
  196.             }
  197.         # Command file
  198.         } -x* {
  199.             if {! [  regexp .\[xX\](.+) $arg ignore cmd_file]} {
  200.                 incr i
  201.                 set cmd_file [ lindex $argv $i ]
  202.             }
  203.             set cmd_fd [open $cmd_file r]
  204.             set cmd_text [read $cmd_fd]
  205.             close $cmd_fd
  206.             set command [join [split $cmd_text \n] \;]
  207.             set do_command 1
  208.         # Do we enable?
  209.         } -noenable {
  210.             set avenable 0
  211.         # Does tacacs automatically enable us?
  212.         } -autoenable {
  213.             set avautoenable 1
  214.             set avenable 0
  215.         } -* {
  216.             send_user "\nError: Unknown argument! $arg\n"
  217.             send_user $usage
  218.             exit 1
  219.         } default {
  220.             break
  221.         }
  222.     }
  223. }
  224. # Process routers...no routers listed is an error.
  225. if { $i == $argc } {
  226.     send_user "\nError: $usage"
  227. }
  228.  
  229. # Only be quiet if we are running a script (it can log its output
  230. # on its own)
  231. if { $do_script } {
  232.     log_user 0
  233. } else {
  234.     log_user 1
  235. }
  236.  
  237. #
  238. # Done configuration/variable setting.  Now run with it...
  239. #
  240.  
  241. # Sets Xterm title if interactive...if its an xterm and the user cares
  242. proc label { host } {
  243.     global env
  244.     # if CLOGIN has an 'x' in it, don't set the xterm name/banner
  245.     if [info exists env(CLOGIN)] {
  246.         if {[string first "x" $env(CLOGIN)] != -1} { return }
  247.     }
  248.     # take host from ENV(TERM)
  249.     if [info exists env(TERM)] {
  250.         if [regexp \^(xterm|vs) $env(TERM) ignore ] {
  251.             send_user "\033]1;[lindex [split $host "."] 0]\a"
  252.             send_user "\033]2;$host\a"
  253.         }
  254.     }
  255. }
  256.  
  257. # This is a helper function to make the password file easier to
  258. # maintain.  Using this the password file has the form:
  259. # add password sl*      pete cow
  260. # add password at*      steve
  261. # add password *        hanky-pie
  262. proc add {var args} { global int_$var ; lappend int_$var $args}
  263. proc include {args} {
  264.     global env
  265.     regsub -all "(^{|}$)" $args {} args
  266.     if { [ regexp "^/" $args ignore ] == 0 } {
  267.         set args $env(HOME)/$args
  268.     }
  269.     source_password_file $args
  270. }
  271.  
  272. proc find {var router} {
  273.     upvar int_$var list
  274.     if { [info exists list] } {
  275.         foreach line $list {
  276.             if { [string match [lindex $line 0] $router ] } {
  277.                 return [lrange $line 1 end]
  278.             }
  279.         }
  280.     }
  281.     return {}
  282. }
  283.  
  284. # Loads the password file.  Note that as this file is tcl, and that
  285. # it is sourced, the user better know what to put in there, as it
  286. # could install more than just password info...  I will assume however,
  287. # that a "bad guy" could just as easy put such code in the clogin
  288. # script, so I will leave .cloginrc as just an extention of that script
  289. proc source_password_file { password_file } {
  290.     global env
  291.     if { ! [file exists $password_file] } {
  292.         send_user "\nError: password file ($password_file) does not exist\n"
  293.         exit 1
  294.     }
  295.     file stat $password_file fileinfo
  296.     if { [expr ($fileinfo(mode) & 007)] != 0000 } {
  297.         send_user "\nError: $password_file must not be world readable/writable\n"
  298.         exit 1
  299.     }
  300.     if [ catch {source $password_file} reason ] {
  301.         send_user "\nError: $reason\n"
  302.         exit 1
  303.     }
  304. }
  305.  
  306. # Log into the router.
  307. # returns: 0 on success, 1 on failure
  308. proc login { router user userpswd passwd enapasswd prompt cmethod cyphertype } {
  309.     global spawn_id in_proc do_command do_script
  310.     global u_prompt p_prompt e_prompt sshcmd
  311.     set in_proc 1
  312.  
  313.     # try each of the connection methods in $cmethod until one is successful
  314.     set progs [llength $cmethod]
  315.     foreach prog [lrange $cmethod 0 end] {
  316.         incr progs -1
  317.         if [string match "telnet*" $prog] {
  318.             regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
  319.             if {"$port" == ""} {
  320.                 set retval [ catch {spawn telnet $router} reason ]
  321.             } else {
  322.                 set retval [ catch {spawn telnet $router $port} reason ]
  323.             }
  324.             if { $retval } {
  325.                 send_user "\nError: telnet failed: $reason\n"
  326.                 return 1
  327.             }
  328.         } elseif ![string compare $prog "ssh"] {
  329.             if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] {
  330.                 send_user "\nError: $sshcmd failed: $reason\n"
  331.                 return 1
  332.             }
  333.         } elseif ![string compare $prog "rsh"] {
  334.             send_error "\nError: unsupported method: rsh\n"
  335.             if { $progs == 0 } {
  336.                 return 1
  337.             }
  338.             continue;
  339.         } else {
  340.             send_user "\nError: unknown connection method: $prog\n"
  341.             return 1
  342.         }
  343.         sleep 0.3
  344.  
  345.         # This helps cleanup each expect clause.
  346.         expect_after {
  347.             timeout {
  348.                 send_user "\nError: TIMEOUT reached\n"
  349.                 catch {close}; catch {wait};
  350.                 if { $in_proc} {
  351.                     return 1
  352.                 } else {
  353.                     continue
  354.                 }
  355.             } eof {
  356.                 send_user "\nError: EOF received\n"
  357.                 catch {close}; catch {wait};
  358.                 if { $in_proc} {
  359.                     return 1
  360.                 } else {
  361.                     continue
  362.                 }
  363.             }
  364.         }
  365.  
  366.     # Here we get a little tricky.  There are several possibilities:
  367.     # the router can ask for a username and passwd and then
  368.     # talk to the TACACS server to authenticate you, or if the
  369.     # TACACS server is not working, then it will use the enable
  370.     # passwd.  Or, the router might not have TACACS turned on,
  371.     # then it will just send the passwd.
  372.     # if telnet fails with connection refused, try ssh
  373.     expect {
  374.         -re "(Connection refused|Secure connection \[^\n\r]+ refused|Connection closed by)" {
  375.             catch {close}; catch {wait};
  376.             if !$progs {
  377.                 send_user "\nError: Connection Refused ($prog)\n"; return 1
  378.             }
  379.         }
  380.         eof { send_user "\nError: Couldn't login\n"; wait; return 1
  381.         } -nocase "unknown host\r" {
  382.             catch {close}; catch {wait};
  383.             send_user "\nError: Unknown host\n"; wait; return 1
  384.         } "Host is unreachable" {
  385.             catch {close}; catch {wait};
  386.             send_user "\nError: Host Unreachable!\n"; wait; return 1
  387.         } "No address associated with name" {
  388.             catch {close}; catch {wait};
  389.             send_user "\nError: Unknown host\n"; wait; return 1
  390.         }
  391.         -re "(Host key not found |The authenticity of host .* be established).*\(yes\/no\)\?" {
  392.             send "yes\r"
  393.             send_user "\nHost $router added to the list of known hosts.\n"
  394.             exp_continue }
  395.         -re "HOST IDENTIFICATION HAS CHANGED.* \(yes\/no\)\?" {
  396.             send "no\r"
  397.             send_user "\nError: The host key for $router has changed.  Update the SSH known_hosts file accordingly.\n"
  398.             return 1
  399.         }
  400.         -re "Offending key for .* \(yes\/no\)\?" {
  401.             send "no\r"
  402.             send_user "\nError: host key mismatch for $router.  Update the SSH known_hosts file accordingly.\n"
  403.             return 1
  404.         }
  405.         -re "Ctrl-Y" { send -- "\031"
  406.             expect {
  407.                -re "$u_prompt" { send -- "$user\r" ; send -- "$userpswd\r" }
  408.                -re "#"   { set in_proc 0; return 0 }
  409.         }
  410.            # exp_continue
  411.         }
  412.         -re "$u_prompt" { send -- "$user\r"
  413.             expect {
  414.                 eof                     { send_user "\nError: Couldn't login\n"; wait; return 1 }
  415.                 "Login invalid"         { send_user "\nError: Invalid login\n";
  416.                                           catch {close}; catch {wait};
  417.                                           return 1 }
  418.                 -re "$p_prompt"         { send -- "$userpswd\r" }
  419.                 "$prompt"               { set in_proc 0; return 0 }
  420.             }
  421.             exp_continue
  422.         }
  423.         -re "$p_prompt" {
  424.             if $in_proc { exp_continue }
  425.             if ![string compare $prog "ssh"] {
  426.                 send -- "$userpswd\r"
  427.             } else {
  428.                 send -- "$passwd\r"
  429.             }
  430.             expect {
  431.                 eof             { send_user "\nError: Couldn't login\n"; wait; return 1 }
  432.                 -re "$e_prompt" { send -- "$enapasswd\r" }
  433.                 "$prompt"       { set in_proc 0; return 0 }
  434.             }
  435.             exp_continue
  436.         }
  437.         #"$prompt"       { break; }
  438.         denied          { send_user "\nError: Check your passwd for $router\n"
  439.                           catch {close}; catch {wait}; return 1
  440.                         }
  441.         "% Bad passwords" {send_user "\nError: Check your passwd for $router\n"; return 1 }
  442.     }
  443. }
  444.     set in_proc 0
  445.     return 0
  446. }
  447.  
  448. # Enable
  449. proc do_enable { enauser enapasswd } {
  450.     global prompt in_proc
  451.     global u_prompt e_prompt
  452.     set in_proc 1
  453.  
  454.     send "enable\r"
  455.     expect {
  456.         -re "$u_prompt" { send -- "$enauser\r"; exp_continue}
  457.         -re "$e_prompt" { send -- "$enapasswd\r"; exp_continue}
  458.         "#"             { set prompt "#" }
  459.         "(enable)"      { set prompt "> (enable) " }
  460.         denied          { send_user "\nError: Check your Enable passwd\n"
  461.                           return 1
  462.                         }
  463.         "% Bad passwords" {
  464.                           send_user "\nError: Check your Enable passwd\n"
  465.                           return 1
  466.                         }
  467.     }
  468.     # We set the prompt variable (above) so script files don't need
  469.     # to know what it is.
  470.     set in_proc 0
  471.     return 0
  472. }
  473.  
  474. # Run commands given on the command line.
  475. proc run_commands { prompt command } {
  476.     global in_proc
  477.     set in_proc 1
  478.  
  479.     regsub -all "\[)(]" $prompt {\\&} reprompt
  480.  
  481.     set commands [split $command \;]
  482.     set num_commands [llength $commands]
  483.     for {set i 0} {$i < $num_commands} { incr i} {
  484.         send -- "[subst -nocommands [lindex $commands $i]]\r"
  485.         expect {
  486.             -re "^\[^\n\r *]*$reprompt"         {}
  487.             -re "^\[^\n\r]*$reprompt."          { exp_continue }
  488.             -re "\[\n\r]+"                      { exp_continue }
  489.             -re "Main Menu"                     { send "L" }
  490.         }
  491.     }
  492.     expect {
  493.         "\n"                                    { exp_continue }
  494.         timeout                                 { catch {close}; catch {wait};
  495.                                                   return 0
  496.                                                 }
  497.         eof                                     { return 0 }
  498.     }
  499.     set in_proc 0
  500. }
  501.  
  502. #
  503. # For each router... (this is main loop)
  504. #
  505. source_password_file $password_file
  506. set in_proc 0
  507. set exitval 0
  508. foreach router [lrange $argv $i end] {
  509.     set router [string tolower $router]
  510.     send_user "$router\n"
  511.  
  512.     # Figure out prompt.
  513.     # Since autoenable is off by default, if we have it defined, it
  514.     # was done on the command line. If it is not specifically set on the
  515.     # command line, check the password file.
  516.     if $avautoenable {
  517.         set autoenable 1
  518.         set enable 0
  519.         set prompt "#"
  520.     } else {
  521.         set ae [find autoenable $router]
  522.         if { "$ae" == "1" } {
  523.             set autoenable 1
  524.             set enable 0
  525.             set prompt "#"
  526.         } else {
  527.             set autoenable 0
  528.             set enable $avenable
  529.             set prompt ">"
  530.         }
  531.     }
  532.  
  533.     # look for noenable option in .cloginrc
  534.     if { [find noenable $router] != "" } {
  535.         set enable 0
  536.     }
  537.  
  538.     # Figure out passwords
  539.     if { $do_passwd || $do_enapasswd } {
  540.       set pswd [find password $router]
  541.       if { [llength $pswd] == 0 } {
  542.         send_user "\nError - no password for $router in $password_file.\n"
  543.         continue
  544.       }
  545.       if { $do_enapasswd && $autoenable == 0 && [llength $pswd] < 2 } {
  546.         send_user "\nError - no enable password for $router in $password_file.\n"
  547.         continue
  548.       }
  549.       set passwd [join [lindex $pswd 0] ""]
  550.       set enapasswd [join [lindex $pswd 1] ""]
  551.     } else {
  552.         set passwd $userpasswd
  553.         set enapasswd $enapasswd
  554.     }
  555.  
  556.     # Figure out username
  557.     if {[info exists username]} {
  558.       # command line username
  559.       set ruser $username
  560.     } else {
  561.       set ruser [join [find user $router] ""]
  562.       if { "$ruser" == "" } { set ruser $default_user }
  563.     }
  564.  
  565.     # Figure out username's password (if different from the vty password)
  566.     if {[info exists userpasswd]} {
  567.       # command line username
  568.       set userpswd $userpasswd
  569.     } else {
  570.       set userpswd [join [find userpassword $router] ""]
  571.       if { "$userpswd" == "" } { set userpswd $passwd }
  572.     }
  573.  
  574.     # Figure out enable username
  575.     if {[info exists enausername]} {
  576.       # command line enausername
  577.       set enauser $enausername
  578.     } else {
  579.       set enauser [join [find enauser $router] ""]
  580.       if { "$enauser" == "" } { set enauser $ruser }
  581.     }
  582.  
  583.     # Figure out prompts
  584.     set u_prompt [find userprompt $router]
  585.     if { "$u_prompt" == "" } {
  586.         set u_prompt "(Username|login|user name):"
  587.     } else {
  588.         set u_prompt [join [lindex $u_prompt 0] ""]
  589.     }
  590.     set p_prompt [find passprompt $router]
  591.     if { "$p_prompt" == "" } {
  592.          set p_prompt "(\[Pp]assword|passwd):"
  593.         } else {
  594.         set p_prompt [join [lindex $p_prompt 0] ""]
  595.     }
  596.     set e_prompt [find enableprompt $router]
  597.     if { "$e_prompt" == "" } {
  598.         set e_prompt "\[Pp]assword:"
  599.     } else {
  600.         set e_prompt [join [lindex $e_prompt 0] ""]
  601.     }
  602.  
  603.     # Figure out cypher type
  604.     if {[info exists cypher]} {
  605.       # command line cypher type
  606.       set cyphertype $cypher
  607.     } else {
  608.       set cyphertype [find cyphertype $router]
  609.       if { "$cyphertype" == "" } { set cyphertype "3des" }
  610.     }
  611.  
  612.     # Figure out connection method
  613.     set cmethod [find method $router]
  614.     if { "$cmethod" == "" } { set cmethod {{telnet}} }
  615.  
  616.     # Figure out the SSH executable name
  617.     set sshcmd [find sshcmd $router]
  618.     if { "$sshcmd" == "" } { set sshcmd {ssh} }
  619.  
  620.     # Login to the router
  621.     if {[login $router $ruser $userpswd $passwd $enapasswd $prompt $cmethod $cyphertype]} {
  622.         incr exitval
  623.         continue
  624.     }
  625.     if { $enable } {
  626.         if {[do_enable $enauser $enapasswd]} {
  627.             if { $do_command || $do_script } {
  628.                 incr exitval
  629.                 catch {close}; catch {wait};
  630.                 continue
  631.             }
  632.         }
  633.     }
  634.  
  635.     if { $do_command } {
  636.         if {[run_commands $prompt $command]} {
  637.             incr exitval
  638.             continue
  639.         }
  640.     } elseif { $do_script } {
  641.         expect $prompt  {}
  642.         source $sfile
  643.         catch {close};
  644.     } else {
  645.         label $router
  646.         log_user 1
  647.         interact
  648.     }
  649.  
  650.     # End of for each router
  651.     catch {wait};
  652.     sleep 0.3
  653. }
  654. exit $exitval
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement