We all know that IOS supports TCL scripting. Many of us uses it for different purposes. Some of us uses TCL in IVR/Fax applications, but another frequently usage of TCL is the simple scripts to test reachability:
(tcl)#foreach ip {
+>192.168.1.1
+>150.1.3.3
+>155.1.58.5
+>} {
+>ping $ip rep 3 timeout 1
+>}
Type escape sequence to abort.
Sending 3, 100-byte ICMP Echos to 192.168.1.1, timeout is 1 seconds:
...
Success rate is 0 percent (0/3)
Type escape sequence to abort.
Sending 3, 100-byte ICMP Echos to 150.1.3.3, timeout is 1 seconds:
...
Success rate is 0 percent (0/3)
Type escape sequence to abort.
Sending 3, 100-byte ICMP Echos to 155.1.58.5, timeout is 1 seconds:
!!!
Success rate is 100 percent (3/3), round-trip min/avg/max = 8/13/20 ms
I often use another script "for start test next command" when working with INE workbook volume 1 to test reachability for each loopback address in the network:
(tcl)#for {set i 1} {$i < 11} {incr i} {
ping 150.1.$i.$i rep 3 time 1 }
Type escape sequence to abort.
Sending 3, 100-byte ICMP Echos to 150.1.1.1, timeout is 1 seconds:
...
Success rate is 0 percent (0/3)
Type escape sequence to abort.
Sending 3, 100-byte ICMP Echos to 150.1.2.2, timeout is 1 seconds:
...
Success rate is 0 percent (0/3)
Type escape sequence to abort.
Sending 3, 100-byte ICMP Echos to 150.1.3.3, timeout is 1 seconds:
!!!
Success rate is 100 percent (3/3), round-trip min/avg/max = 8/108/292 ms
and so on for ten addresses, output omitted.
Note the difference to the following script:
for {set $i 1} {$i < 11} {incr $i} {
+>ping 150.1.$i.$i rep 3 time 1 }
Do you see the difference? There is a dollar sign added to the variable $i in “set” and “incr” statements.
The result will be lamentable:
Type escape sequence to abort.
Sending 3, 100-byte ICMP Echos to 150.1.1.1, timeout is 1 seconds:
...
Success rate is 0 percent (0/3)
Type escape sequence to abort.
Sending 3, 100-byte ICMP Echos to 150.1.1.1, timeout is 1 seconds:
...
Success rate is 0 percent (0/3)
Type escape sequence to abort.
Sending 3, 100-byte ICMP Echos to 150.1.1.1, timeout is 1 seconds:
...
Success rate is 0 percent (0/3)
Type escape sequence to abort.
And so on infinitively. You can not even interrupt it with help of ctrl+shift+6 combination. It will stops only one ping command at once. You will be required to reboot your device to stop this. In the real CCIE lab or production network it can be dangerous and very time wasting.
This infinite loop happens because there is two variables really - “i” and “$i” and operations should reference them as “$i” and “$$i”, but $i variable is not defined yet:
(tcl)#for {set $i 1} {$$i < 11} {incr $i} {
+>ping 150.1.$$i.$$i rep 3 time 1 }
can't read "i": no such variable
+>ping 150.1.$$i.$$i rep 3 time 1 }
can't read "i": no such variable
This is very easy and basic problem for anybody who was learning non-interpreted programming languages, but with interpreted script languages such as TCL it can be tricky if you is a network engineer with no programming experience although I hope here is no such people already ;)
Комментариев нет:
Отправить комментарий