Posted to tcl by zmoment at Wed May 10 18:29:26 GMT 2023view raw

  1. #!/bin/sh
  2. # the next line restarts using tclsh \
  3. exec tclsh "$0" ${1+"$@"}
  4.  
  5. proc receive {fd host} {
  6. if {[eof $fd]} {
  7. chan configure $fd -blocking 1
  8. if {[catch {close $fd} err info]} {
  9. puts "$host :::: [dict get $info -errorcode]"
  10. }
  11. incr ::pipe_exit
  12. } elseif {[gets $fd line] >= 0} {
  13. #puts "$host: $line"
  14. }
  15. }
  16. set pipe_exit 0
  17. set hostnames [list devuan alpine 192.168.1.253]
  18. foreach host $hostnames {
  19. set pipe [open |[list ping -W 3 -c 1 $host]]
  20. chan configure $pipe -blocking 0
  21. chan event $pipe readable [list receive $pipe $host]
  22. }
  23.  
  24. while {$pipe_exit < [llength $hostnames]} {
  25. vwait pipe_exit
  26. }