From bc1ec6ba8acb655be5ea25aa5ed5cdb6d114e5ce Mon Sep 17 00:00:00 2001
From: Tim Niemeyer <tim.niemeyer@mastersword.de>
Date: Sun, 5 May 2013 22:07:50 +0200
Subject: [PATCH] ath9k-watchdog: refresh update URL before upload

It seems that the uci stuff isn't ready when the script is started.

Signed-off-by: Tim Niemeyer <tim.niemeyer@mastersword.de>
---
 ath9k-watchdog/files/ath9k-watchdog-pm | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ath9k-watchdog/files/ath9k-watchdog-pm b/ath9k-watchdog/files/ath9k-watchdog-pm
index d984be0..93dff26 100755
--- a/ath9k-watchdog/files/ath9k-watchdog-pm
+++ b/ath9k-watchdog/files/ath9k-watchdog-pm
@@ -1,7 +1,6 @@
 #!/bin/sh
 # Save log
 mkdir -p /usr/lib/ath9k-watchdog
-UPLOAD_URL="http://[$(uci get configurator.@api[0].ipv6_address)%$(uci get configurator.@api[0].ipv6_interface)]/api/rest/event/"
 WGETC=$(which wget)
 
 
@@ -11,11 +10,16 @@ cd /usr/lib/ath9k-watchdog
 #Poll directory every 60 secs
 while [ 1 = 1 ]
 do
-	for f in $(ls .); do 
-		$WGETC -q $UPLOAD_URL"?api_key=$(uci get configurator.@api[0].api_key)&object=router&object_id="$(uci get configurator.@crawl[0].router_id)"&action=watchdog_ath9k_bug&"$(cat $f) -O - && rm $f
-	done
+	if [ "$(ls .)" != "" ]
+	then
+		UPLOAD_URL="http://[$(uci get configurator.@api[0].ipv6_address)%$(uci get configurator.@api[0].ipv6_interface)]/api/rest/event/"
+		for f in $(ls .); do 
+			$WGETC -q $UPLOAD_URL"?api_key=$(uci get configurator.@api[0].api_key)&object=router&object_id="$(uci get configurator.@crawl[0].router_id)"&action=watchdog_ath9k_bug&"$(cat $f) -O - && rm $f
+		done
+		# If there are more than 15 files, assume that files cannot be uploaded
+		# Delete oldest files in order to avoid jffs-overflow
+		ls -t | sed -e '1,15d' | xargs rm 2> /dev/null
+	fi
+	
 	sleep 60
-	# If there are more than 15 files, assume that files cannot be uploaded
-	# Delete oldest files in order to avoid jffs-overflow
-	ls -t | sed -e '1,15d' | xargs rm 2> /dev/null
 done
-- 
GitLab