これは、アルゴリズムの興味深いスピンです...すべての行を反復処理する際に現在発生している問題は、記述されたスクリプトが、行の1つに表示されるだけで終了することです...
for {set i 0} {$i == 4} {incr i} {
send "clear line vty $i\r"
"confirm]" {send "\r"}
"% Not allowed" {send "quit\r"; exit}
}
が表示された場合は% Not allowed
、スクリプトを終了する代わりに、この行をバイパスして次の行に移動してください...
for {set i 0} {$i < 4} {incr i} {
send "clear line vty $i\r"
expect {
"confirm]" { send "\r"; expect "*#" }
"% Not allowed" { send "! refusing to clear line vty $i\r"; expect "*#" }
}
}
Cisco IOSは、行が次で始まる場合、コメントと見なします。!
次のスクリプトはログインし、スクリプトが実行されている行を除くすべての行をクリアします...これは私のラボでは正常に実行されます。
#!/usr/bin/expect -f
spawn telnet 172.16.1.5
set user [lindex $argv 0]
set pass [lindex $argv 1]
expect "Username: "
send "$user\r"
expect "assword: "
send "$pass\r"
expect ">"
send "enable\r"
expect "assword: "
send "$pass\r"
expect "*#"
for {set i 0} {$i < 5} {incr i} {
send "clear line vty $i\r"
expect {
"confirm]" { send "\r"; expect "*#" }
"% Not allowed" { send "! refusing to clear line vty $i\r"; expect "*#" }
}
}
exit