#!/usr/bin/expect -f
proc ap_to_file {file string} {
set log [open $file a]
puts $log $string
close $log
}
set log_file_name log_[join [split [clock format \
[clock seconds] -format %D/%H/%M/%S] /] "_"]
set f_log [open $log_file_name w]
close $f_log
if { [file exist $argv ] } {
set f_details [open $argv r]
} else {
puts "Invalid file name $argv";
return;
}
gets $f_details line
set delay [lindex $line 0]
set limit [lindex $line 1]
while { [gets $f_details line] != "-1" } {
lappend details [lindex [split $line ,] 0]
lappend details [lindex [split $line ,] 1]
lappend details [lindex [split $line ,] 2]
lappend details [lindex [split $line ,] 3]
lappend details [lindex [split $line ,] 4]
puts "$line"
}
close $f_details
set match_max 300000
for { set i 1 } { $i <= $limit } { incr i } {
ap_to_file $log_file_name "
---------------------
Iteration $i starts
---------------------
"
foreach { ip_connect slot_list user pwd dbg_pwd } $details {
if { $ip_connect == "" } {
puts "ip value Null";
return;
}
while { [catch {spawn telnet $ip_connect} err] == 1 } {
puts "Couldn't connect to $ip_connect ; retrying after 5 seconds"
after 5000
}
expect login
send $user\r
expect "password"
send "$pwd\r"
ap_to_file $log_file_name "-----------------------------------"
ap_to_file $log_file_name "Entering switch $ip_connect"
ap_to_file $log_file_name "-----------------------------------"
expect " # "
ap_to_file $log_file_name $expect_out(buffer);
send "disable clipaging\r"
expect " # "
ap_to_file $log_file_name $expect_out(buffer);
send "show version\r";
expect "#"
ap_to_file $log_file_name $expect_out(buffer);
send "show log\r";
expect {
"*\n" {
ap_to_file $log_file_name $expect_out(buffer);
exp_continue;
}
" # " { }
}
send "show memory\r";
expect {
"*\n" {
ap_to_file $log_file_name $expect_out(buffer);
exp_continue;
}
" # " { }
}
ap_to_file $log_file_name $expect_out(buffer);
send "enable debug-mode\r";
expect "EXOS*password:";
ap_to_file $log_file_name $expect_out(buffer);
send $dbg_pwd\r;
expect "debug*#"
ap_to_file $log_file_name $expect_out(buffer);
send "debug hal show sys-health-check\r";
expect {
"*\n" {
ap_to_file $log_file_name $expect_out(buffer);
exp_continue;
}
" # " { }
}
ap_to_file $log_file_name $expect_out(buffer);
send "debug hal show platform fdb 11\r";
expect {
"*\n" {
ap_to_file $log_file_name $expect_out(buffer);
exp_continue;
}
" # " { }
}
ap_to_file $log_file_name $expect_out(buffer);
send "debug msg show msg\r";
expect {
"*\n" {
ap_to_file $log_file_name $expect_out(buffer);
exp_continue;
}
" # " { }
}
ap_to_file $log_file_name $expect_out(buffer);
foreach slot $slot_list {
ap_to_file $log_file_name " --------------------------------"
ap_to_file $log_file_name " Entering slot $slot"
ap_to_file $log_file_name " --------------------------------"
send "!telnet -v1 10.0.$slot.2\r";
expect "~ #";
ap_to_file $log_file_name $expect_out(buffer);
send "cat /proc/meminfo_better\r";
expect "~ #";
ap_to_file $log_file_name $expect_out(buffer);
send "cat /proc/slabinfo\r";
expect {
"*\n" {
ap_to_file $log_file_name $expect_out(buffer);
exp_continue;
}
"~ #" { }
}
send "top -b -n1 | head -n20\r";
expect "~ #";
ap_to_file $log_file_name $expect_out(buffer);
ap_to_file $log_file_name " --------------------------------"
ap_to_file $log_file_name " Entering BCM shell"
ap_to_file $log_file_name " --------------------------------"
send "/extr/bin/bcm.shell\r";
send "\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "0:\r";
expect "BCM*>"
ap_to_file $log_file_name $expect_out(buffer);
send "async\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "soc\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "show error\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "get L2_ENTRY_PARITY_STATUS\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "get L3_DEFIP_PARITY_STATUS\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
ap_to_file $log_file_name " ------------------------------"
ap_to_file $log_file_name " Switching to unit 1"
ap_to_file $log_file_name " ------------------------------"
send "1:\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "async\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "soc\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "show error\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "get L2_ENTRY_PARITY_STATUS\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "get L3_DEFIP_PARITY_STATUS\r";
expect "BCM*>";
ap_to_file $log_file_name $expect_out(buffer);
send "0:\r"
expect "BCM*>"
send "quit\r";
expect "~ #";
ap_to_file $log_file_name $expect_out(buffer);
send "exit\r";
expect " # ";
ap_to_file $log_file_name $expect_out(buffer);
}
send logout\r;
}
if { $i != $limit } {
after [expr $delay * 1000];
}
ap_to_file $log_file_name "
------------------------
Iteration $i done
------------------------"
}
puts ""
puts "-----------------------"
puts "logs are available at ./$log_file_name"
puts "-----------------------"
No comments:
Post a Comment