Basic ping testing using tclsh on Mac OSX

193 Views Asked by At

I can't seem to modify the tclsh script I use for Cisco to test basic ping reachability on my Mac OSX.

I swap the ping to ping -c 2 $ip.

Can anyone help solve this?

Thanks.

proc PI {} {
    foreach ip {
        155.1.45.5
        155.1.0.3
     } { exec [ping $ip timeout 1 r 2 ] }
}
1

There are 1 best solutions below

1
On

The basic fix to your code is to drop those [brackets]; brackets in Tcl are like ` in the Unix shell. (But nestable.)

You want the ping to be run by a sub-process, so you want to pass the name ping to exec, which runs sub-processes.

proc PI {} {
    foreach ip { 155.1.45.5 155.1.0.3 } {
        exec ping -c 2 -t 1 $ip
    }
}

You might also need to consider what to do with the results from the ping. Right now, you'll get an error if anything is unreachable. (Also be aware that the syntax of ping varies between systems; using it isn't very portable…)