#!/bin/bash
# copyright 2009: Antoine Durand-Gasselin <adg@crans.org>
# license: BSD 3-clauses

if [[ $# -lt 1 ]]; then
    cat <<EOF
usage: uname_bornes.sh CMD ARGS
examples:
uname_bornes.sh uname -v
  affiche la version du firmware sur les bornes
uname_bornes.sh uptime
  affiche l'uptime
EOF
    exit 1
fi

pids=""
(for borne in $(host -l wifi.crans.org | grep 138.231.148 | \
               grep -v '138.231.148.1$' | awk '{print $1}');
do
    ssh ${borne/.crans.org/} -o Connecttimeout=1 "printf '%-15s%s\n' ${borne/.wifi.crans.org/} \"\`$@\`\"" & pids="$pids $!"
    sleep 0.001 # pour que les bornes sortent dans l'ordre
done

for pid in $pids; do
    wait $pid
done) | sort
