From fb41f2ece4fef070a59f18ee969f0b7a3c4f7331 Mon Sep 17 00:00:00 2001
From: David Beniamine <david.beniamine@tetras-libre.fr>
Date: Thu, 2 Aug 2018 13:21:22 +0200
Subject: [PATCH] Small fixes

---
 wol/scripts/sendmac.sh          |  2 +-
 wol/scripts/wakeonlanservice.sh | 33 ++++++++++++++++-----------------
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/wol/scripts/sendmac.sh b/wol/scripts/sendmac.sh
index fd7abfc..1f7ac2a 100755
--- a/wol/scripts/sendmac.sh
+++ b/wol/scripts/sendmac.sh
@@ -19,7 +19,7 @@
 IP=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1)
 netcat="netcat -l $IP 9999"
 KPID=`ps aux | grep \'$netcat\' | awk '{print $2}'`
-[ ! -z "$PID" ] && kill $PID
+[ ! -z "$KPID" ] && kill $KPID
 
 subnet=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1 | cut -d . -f 1-3)
 echo "$1" | netcat $subnet.52 9999
diff --git a/wol/scripts/wakeonlanservice.sh b/wol/scripts/wakeonlanservice.sh
index adbdcda..375c6fe 100755
--- a/wol/scripts/wakeonlanservice.sh
+++ b/wol/scripts/wakeonlanservice.sh
@@ -24,20 +24,19 @@ getip(){
 IP=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1)
 broadcast=$(ip a | awk '/inet.*eth1/ {print $4}' | cut -d / -f 1)
 subnet=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1 | cut -d . -f 1-3)
-netcat -k -l $IP 9999 | \
-    while read MAC
-    do
-        if [ $(echo "$MAC" | egrep -c "^([0-9a-f]{2}:?){6}$") -eq 1 ]
-        then
-            wakeonlan -i $broadcast "$MAC"
-            bootedip=""
-            sleep 25
-            while [ -z "$bootedip" ]
-            do
-                bootedip=`getip $MAC`
-                sleep 5
-            done
-            echo "$bootedip" | netcat $subnet.51 9999
-        fi
-    done
-
+while true
+do
+    MAC=`netcat -k -l $IP 9999`
+    if [ $(echo "$MAC" | egrep -c "^([0-9a-f]{2}:?){6}$") -eq 1 ]
+    then
+        wakeonlan -i $broadcast "$MAC"
+        bootedip=""
+        sleep 25
+        while [ -z "$bootedip" ]
+        do
+            bootedip=`getip $MAC`
+            sleep 5
+        done
+        echo "$bootedip" | netcat $subnet.51 9999
+    fi
+done
-- 
GitLab