3 # ============================================================================
5 # Copyright (C) THALES. All rights reserved
6 # Author: Laurent Mazet
8 # Gestion attente switches au boot (ping,telnet)
9 # ============================================================================
15 PROGNAME
=$
(basename $0)
20 echo "usage: $PROGNAME [-c command] [-h] [-i] [-o] [-t seconds] [-v] [-w] [-x] host1 host2..."
21 echo " -c: set command (default '$CMD')"
22 echo " -h: help message"
23 echo " -i: infinity loop mode [default]"
24 echo " -o: only try ones"
26 echo " -v: version message"
31 while [ $# -gt 0 ]; do
33 -c) shift; CMD
+=" -c '${1// /@@}'";;
37 -t) shift; [[ "$1" =~
[^
0-9] ]] && { echo "incorrect timeout ($1)"; exit 1;}; TIMEOUT
=$1;;
38 -v) echo "$PROGNAME: version $VER"; exit;;
46 [ "$list" ] || list
=$
(awk '{sub(/#.*/, "")} /sw[gm]/ {print $2}' /etc
/hosts
)
50 if [ "$TIMEOUT" ]; then
51 trap "echo 'timeout expired (${TIMEOUT}s)'; exit 0;" SIGVTALRM
52 ( sleep $TIMEOUT; kill -SIGVTALRM $$
2>/dev
/null
; [ $?
-eq 0 ] && rc
=1 || rc
=0; exit $rc) &
61 ping -c 1 $host >&/dev
/null
&& { log
=$
(eval /opt
/script
/connect_switch
$host ${CMD//@@/ } -c exit 2>/dev/null) && stat=1; echo ${log:=soon..} | sed 's/\r/\n'$host:' /g'; } ||
echo
62 [ "$MODE" = "wait" -a $stat -eq 1 ] && list
=${list/$host }
64 [ "$MODE" = "ones" ] && break;
65 [[ "$list" =~
[a-zA-Z0-9_-
] ]] && sleep 1 ||
break;