clean code
authorLaurent Mazet <laurent.mazet@thalesgroup.com>
Wed, 3 Dec 2014 17:26:34 +0000 (18:26 +0100)
committerLaurent Mazet <laurent.mazet@thalesgroup.com>
Wed, 3 Dec 2014 17:26:34 +0000 (18:26 +0100)
master/etc/init.d/etherwake
master/etc/init.d/wakeonlan

index 401992e9c37564c16bdf113271e9eba2a61b6636..d23bccb09a3d660dc8736fafadebb71cb5b76501 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
-VER=1.3
+VER=1.4
 # ============================================================================
 #
 # Copyright (C) THALES. All rights reserved
@@ -13,6 +13,8 @@ VER=1.3
 #   temps entre 2 wake
 # - V1.3: Laurent Mazet 02/05/2013
 #   Daemonisation
+# - V1.4: Laurent Mazet & Thomas Perennou 03/12/2014
+#   Legers correctifs
 # ============================================================================
 
 ### BEGIN INIT INFO
@@ -45,10 +47,10 @@ do_start () {
     n=0
     while [ $NB_TRY -gt 0 ]; do
 
-        for mac in $(awk '{sub(/#.*/, "")} /trc[0-9]/ {gsub(/;/, " "); print $6}' $DHCPCONF); do
-            host=$(awk '{sub(/#.*/, "")} /'$mac'/ {print $2}' $DHCPCONF)
+        for mac in $(awk '{sub(/#.*/, "")} /trc[0-9]/ {gsub(/[;{}]/, " "); print $5}' $DHCPCONF); do
+            host=$(awk '{sub(/#.*/, "")} /'$mac'/ {gsub(/[{}]/, " "); print $2}' $DHCPCONF)
 
-            log_action_msg "Wake-up $host ($mac)"
+            log_action_msg "Wake-up $host (EtherWake $mac)"
             etherwake $mac
 
            n=$(expr $n + 1)
index 2a36ed8244595b3508fcfc7f8002e250a1a16252..1c360cecfc326d990492f5c1594de65842b58ff4 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
-VER=1.3
+VER=1.5
 # ============================================================================
 #
 # Copyright (C) THALES. All rights reserved
@@ -13,6 +13,8 @@ VER=1.3
 #   et de broadcast
 # - V1.4: Laurent Mazet 09/05/2014
 #   Daemonisation
+# - V1.5: Laurent Mazet & Thomas Perennou 03/12/2014
+#   Legers correctifs
 # ============================================================================
 
 ### BEGIN INIT INFO
@@ -39,12 +41,11 @@ do_start () {
 
     log_action_msg "Activate Wake On Lan"
 
-    mac=$(awk '{ sub(/#.*/, "") } /trc[0-9]/ { gsub(/;/, " "); print $6}' $DHCPCONF)
-
-    for m in $mac; do
-       broadcast=$(grep $m /etc/dhcp/dhcpd.conf | sed 's/.* \([0-9.]*\)\..*/\1.255/')
-        log_action_msg "Wake-up $broadcast ($m)"
-        wakeonlan -p 7 -i $broadcast $m
+    for mac in $(awk '{ sub(/#.*/, "") } /trc[0-9]/ { gsub(/[;{}]/, " "); print $5}' $DHCPCONF); do
+       broadcast=$(grep $mac $DHCPCONF | sed 's/.* \([0-9.]*\)\..*/\1.255/')
+        host=$(awk '{sub(/#.*/, "")} /'$mac'/ {gsub(/[{}]/, " "); print $2}' $DHCPCONF)
+        log_action_msg "Wake-up $host (WOL $mac $broadcast)"
+        wakeonlan -p 7 -i $broadcast $mac
     done
 }