The foreach
, as you write it in your question, appears correct. (If there was one more argument, you'd get the message from the question title, but your code sample shouldn't generate that.) It's more likely that the ping
you are calling doesn't write anything visible, and instead just produces the result as a string. That's pretty common with Tcl code. I'd expect something like this to work, assuming my diagnosis is correct:
foreach address {
192.168.1.1
192.168.1.2
172.16.224.5
172.16.224.6
192.168.72.1
172.16.224.2
172.16.224.1
10.2.1.1
10.2.2.1
} {
puts [ping $address]
}
I've omitted the prompts and added indents and a few more newlines for clarity. If ping
is really an external command, use exec ping $address
instead (it's considered bad form to rely on the unknown command handling to bring external commands into your code, especially as it is disabled in scripted mode.) With an external command, you might also want to pass the -c
option with a number so as to limit the number of requests used to a fairly small number, perhaps:
puts [exec ping -c 5 $address]
Be aware that the set of commands supported by a Tcl interpreter can be changed completely (by design) and that the commands listed in the documentation are really just a pre-supplied standard library. When Tcl is embedded in an environment like a router, it is quite possible that things have been changed around a fair bit. (It's not like it's hard for the router vendor to do it.) That means that surprising differences in commands most certainly can occur, and that you should check the documentation you've got and proceed with a little thought instead of just blindly trusting what I wrote.