chrpinedo / rancid-cisco-sb

rancid-cisco-sb
26 stars 25 forks source link

csblogin doesn't work with config prompts #17

Closed ganeshv closed 8 years ago

ganeshv commented 8 years ago

Using an SG300, normal commands like

 csblogin -c "show cpu utilization;show cpu utilization" switch2

work fine. However, commands like config which change the prompt run into trouble. e.g.

 csblogin -c "config;exit" switch2

logins run, runs the command config and then gets stuck. Output:

 User Name:cisco
 Password:********

 switch788b4a#terminal datadump
 switch788b4a#config
 switch788b4a(config)#
chrpinedo commented 8 years ago

This is difficult for me to debug because I don't have a switch to test the scripts. However, you could try several options to try to solve yourselft the problem:

  1. Launch the script in debug mode. Perhaps it would provide more information...
csblogin -d -c "config;exit" switch2
  1. Inside the csblogin, I think the important code fragment is in line 465. This is the for loop that launches the commands and waits for the desired output. Perhaps, the regular expressions should be customized.
for {set i 0} {$i < $num_commands} { incr i} {
    send "[lindex $commands $i]\r"
    expect {
         -re "^\[^\n\r *]*$prompt *$"    {}  
         -re "^\[^\n\r]*$prompt."        { exp_continue }
         -re "(\r\n|\n)"                 { exp_continue }
     }   
}   
ganeshv commented 8 years ago

Thanks. I already tried -d but it was hopelessly verbose.

I tried changing that last regex case to

     -re "\[\r\n]+"                 { exp_continue }

and it seems to work for both prompt-changing commands like config;exit, config;vlan database;exit;exit and regular commands like show cpu utilization; show cpu utilization. Don't have a comprehensive list of test cases though.

chrpinedo commented 8 years ago

csbrancid script launches csblogin script with commands "show system;show version;show startup-config". Could you verify your modified version of csblogin with these commands? If it is ok, I would upgrade the csblogin script with your modification.

chrpinedo commented 8 years ago

solved with #18