From da376b5ff488e5040d840220e477ba53ae9e63f8 Mon Sep 17 00:00:00 2001
From: David Beniamine <david.beniamine@tetras-libre.fr>
Date: Mon, 5 Aug 2019 14:01:32 +0200
Subject: [PATCH] Transmit file in one netcat

---
 wol/scripts/get_registry.sh     | 13 ++++---------
 wol/scripts/wakeonlanservice.sh |  7 +------
 2 files changed, 5 insertions(+), 15 deletions(-)
 mode change 100644 => 100755 wol/scripts/get_registry.sh

diff --git a/wol/scripts/get_registry.sh b/wol/scripts/get_registry.sh
old mode 100644
new mode 100755
index 38c171f..7dd7c7b
--- a/wol/scripts/get_registry.sh
+++ b/wol/scripts/get_registry.sh
@@ -17,18 +17,13 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 IP=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1)
-netcat="netcat -l $IP 9999"
+port=9999
+netcat="netcat -l $IP $port"
 KPID=`ps aux | grep "$netcat" | awk '{print $2}'`
-[ ! -z "$KPID" ] && kill $KPID
+[ ! -z "$KPID" ] && kill $KPID > /dev/null 2>&1
 
 subnet=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1 | cut -d . -f 1-3)
 host=$subnet.52
-port=9999
 
 echo "get_registry" | netcat $host $port
-nline=$($netcat | cut -d ' ' -f 1)
-i=0;
-for i in $(seq 1 $nline)
-do
-    $netcat
-done
+stdbuf -i0 $netcat
diff --git a/wol/scripts/wakeonlanservice.sh b/wol/scripts/wakeonlanservice.sh
index 8f61fcf..5823e5c 100755
--- a/wol/scripts/wakeonlanservice.sh
+++ b/wol/scripts/wakeonlanservice.sh
@@ -47,11 +47,6 @@ do
         done
     elif [ $MAC == "get_registry" ]
     then
-        hostfile="/etc/registry/hosts"
-        wc -l $hostfile | netcat $host $port
-        while read line
-        do
-            echo "$line" | netcat $host $port
-        done < $hostfile
+        stdbuf -oL cat /etc/registry/hosts | netcat $host $port
     fi
 done
-- 
GitLab