ControlScripts: add script to detect complete transfer for hrktorrent
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 30 Jul 2010 11:44:57 +0000 (14:44 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 30 Jul 2010 11:44:57 +0000 (14:44 +0300)
ControlScripts/detect_stopped_hrk.sh [new file with mode: 0755]

diff --git a/ControlScripts/detect_stopped_hrk.sh b/ControlScripts/detect_stopped_hrk.sh
new file mode 100755 (executable)
index 0000000..e475752
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# Copyright: George Milescu 2010 - george.milescu@gmail.com
+#
+# Bash script used to detect when a regular client finished downloading a torrent
+# The script
+#  * monitors a log file provided as an argument
+#  * as long as the doe is not finished the script keeps running
+#  * when the doe is finished it returns 0
+#  * blocks the caller - the script exits only when the doe has completed the download
+#
+# Script arguments:
+#  * log file
+
+if [ ! $# -eq 1 ]; then
+       echo "usage: $0 log-file"
+       exit 1
+fi
+
+LOG_FILE=$1
+
+while true; do
+       if cat $LOG_FILE | grep "Torrent finished" &> /dev/null; then
+               exit 0
+       fi
+       
+       # Don't do continuous polling
+       sleep 5
+done