ControlScripts: parse hrktorrent output file
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 30 Jul 2010 11:41:17 +0000 (14:41 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 30 Jul 2010 11:41:17 +0000 (14:41 +0300)
ControlScripts/parse_hrk.sh [new file with mode: 0755]

diff --git a/ControlScripts/parse_hrk.sh b/ControlScripts/parse_hrk.sh
new file mode 100755 (executable)
index 0000000..694d37f
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/bash
+#
+# 2010 Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
+#
+# Bash script used to parse the log file generated by a seeder client and to generate a data file
+# The script
+#  * TODO
+#
+# Script arguments:
+#  * a folder where the log and data files are stored
+#  * the name of a log file in that folder
+
+
+if [ ! $# -eq 2 ]; then
+       echo "usage: $0 log-folder log-file"
+       exit 1
+fi
+
+LOG_FOLDER=$1
+LOG_FILE=$2
+DATA_FILE=$LOG_FOLDER/${LOG_FILE}.data
+
+# Check if the log folder exists
+if [ ! -d $LOG_FOLDER ]; then
+       echo "Error: The folder $LOG_FOLDER does not exist."
+       exit 1
+fi
+
+# Check if the log file exists
+if [ ! -e $LOG_FOLDER/$LOG_FILE ]; then
+       echo "Error: The log file $LOG_FOLDER/$LOG_FILE does not exist."
+       exit 1
+fi
+
+# Check if the log file is a regular file
+if [ ! -f $LOG_FOLDER/$LOG_FILE ]; then
+       echo "Error: The log file $LOG_FOLDER/$LOG_FILE is not a regular file."
+       exit 1
+fi
+
+# Write the header to the data file
+echo "time percent upspeed dlspeed" > $DATA_FILE
+
+# Clean and parse the log file
+grep '^ps' $LOG_FOLDER/$LOG_FILE | awk -F '[ \t<>:,]+' '
+{
+       idx = match($10, "^[0-9]+");
+       download = substr($10, idx, RLENGTH);
+       idx = match($14, "^[0-9]+");
+       size = substr($14, idx, RLENGTH);
+
+       percent = 100 * download / size;
+       percent_string = sprintf("%.2f", percent);
+       print percent, $6, $8;
+}' | cat -b >> $DATA_FILE
+
+exit 0