From 47c5bc6d081597f1963b8cf43722b98a7c8fc1c9 Mon Sep 17 00:00:00 2001
From: Loic Guegan <manzerbredes@mailbox.org>
Date: Sat, 28 Oct 2023 14:34:45 +0200
Subject: [PATCH] Minor changes

---
 .clusterman.sh | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/.clusterman.sh b/.clusterman.sh
index 9c86313..8da5146 100755
--- a/.clusterman.sh
+++ b/.clusterman.sh
@@ -1,4 +1,6 @@
 #!/usr/bin/env bash
+# This script assumes that the keys used by publishers
+# corresponds to the UNIQUE hostname of each monitored node
 
 # Check parameters
 [ $# -ne 3 ] && { echo "Usage: $0 <key> <from> <to>"; exit 1; }
@@ -16,3 +18,36 @@ source ${wai}/config.mk
 ifrom=$(echo $from $LOG_INTERVAL | awk '{print($1-($1%$2))}')
 ito=$(echo $to $LOG_INTERVAL | awk '{print($1-($1%$2))}')
 
+# Search for power measurements
+nfolder=$(readlink -f ${wai}/${SUBSCRIBER_DIR}/$key/) # Node Folder
+[ ! -d "$nfolder" ] && { echo "Node \"$key\" has not power measurements."; exit 2; }
+cfolder=${nfolder}/$(ls $nfolder/|head -n1)/ # Client FOlder
+[ ! -d "$cfolder" ] && { echo "Node \"$key\" has no client folder yet."; exit 3; }
+# Set from file and to file
+ffile=${cfolder}/$ifrom
+tfile=${cfolder}/$ito
+[ ! -f "$ffile" ] && { echo "Node power measurements starting at $2."; exit 4; }
+[ ! -f "$tfile" ] && { echo "Node power measurements up to $3."; exit 5; }
+# Give files to the user
+missings=0
+header=0
+for interval in $(seq $ifrom $LOG_INTERVAL $ito)
+do
+    file=${cfolder}/${interval}
+    if [ ! -f "$file" ]
+    then
+        missings=$(( missings + 1 ))
+        continue
+    fi
+    # Cat files
+    if [ $header -eq 0 ]
+    then
+        cat $file
+        header=1
+    else
+        tail -n +2 $file
+    fi
+done
+
+# Report missings
+[ $missings -gt 0 ] && { echo "Some power measurements are missings ($missings intervals of ${LOG_INTERVAL}s)" >&2; exit 6; }