From: Razvan Deaconescu Date: Fri, 30 Jul 2010 11:41:17 +0000 (+0300) Subject: ControlScripts: parse hrktorrent output file X-Git-Tag: classic-scenario-config~26 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=be0e3acb0714b5a83797e46d70ed63d20b8c311c;p=p2p-testing-infrastructure.git ControlScripts: parse hrktorrent output file --- diff --git a/ControlScripts/parse_hrk.sh b/ControlScripts/parse_hrk.sh new file mode 100755 index 0000000..694d37f --- /dev/null +++ b/ControlScripts/parse_hrk.sh @@ -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