Skip to content

Commit

Permalink
Remove code that doesn't make sense
Browse files Browse the repository at this point in the history
The code does something like this:

        eval spawn  $proto $sshopts $username@$host

where $proto is either "telnet" or "ssh", and then expects a password
prompt, username etc. :

        catch { expect -re  "(assword)|(ser(name)?)|(yes/no)" }

however if no username or password prompt is forthcoming - because f.ex.
the respective ssh connection is configured to do key-based
authentication, then that expect will do nothing at all.

The next line will try to access the expect_out variable, fail and
trigger an exception, which will be handled by the body of the "if"
condition:

        if { [ catch { set loginbuf "$expect_out(0,string)" } ] } {
                [...]
                set loginbuf $expect_out(0,string)

Given however, that accessing "expect_out(0,string)" triggered the
exception in the first place, accessing that same variable again in the
exception handler will trigger the exception again:

can't read "expect_out(0,string)": no such element in array
    while executing
"set loginbuf $expect_out(0,string)"
    ("foreach" body line 35)
    invoked from within
"foreach host $hostlist {
        #####################
        # Login to the host #
        #####################

        if { [ info exist debugfile ] } {
                if { $FORK == 1 ||..."
    (file "/home/tpo/bin/ciscocmd" line 444)

(note that the line numbers are not correct - due to other causes).

Since the variable "loginbuf" in the line
"set loginbuf $expect_out(0,string)" doesn't seem to be used
anyway, I'm deleting that line of code and thus removing the
error/exception displayed above.
  • Loading branch information
tpo committed Jun 13, 2018
1 parent 07868c0 commit d42e317
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion ciscocmd
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ foreach host $hostlist {
# if { [ catch { set loginbuf "$expect_out(2,string)" } ] } {
# set loginbuf "$expect_out(3,string)"
# }
set loginbuf $expect_out(0,string)
send_user "$host failed to connect\n"
if { [info exist forcenext] } {
# force next host
Expand Down

0 comments on commit d42e317

Please sign in to comment.