The logger has been updated, it now saves multiple log files with running numbering.
#!/bin/bash
# Bitfury chainminer logfile consolidation script
# Jlsminingcorp and Isokivi, September 2013
# Version 1.4
# User configurable variables
# $logfile is the path to the bitfury chainminer log file
# $output is the path to the board-data output file that you would like to write to
# $outputdir is the directory to store output in
# $logtime is the time (in minutes) to collect data for
# $numboards is the number of H-boards your the miner
logfile="/run/shm/.stat.log"
output="boards.log"
outputdir="."
logtime="0"
numboards="2"
# Timestamps
datestamp=$(ls --full-time "$logfile" | awk '{print $6}')
timestamp=$(ls --full-time "$logfile" | awk '{print $7}' | awk -F"." '{print $1}')
# If log file or output files don't exist then take appropriate action
if [ ! -e "$logfile" ]; then
echo "$(date)"" : ""Logfile does not exist in the specified location"
echo "$(date)"" : ""Logfile does not exist in the specified location" >> "$output"
exit 1
fi
if [ ! -d "$outputdir"/old_logs ]; then
mkdir "$outputdir"/old_logs
fi
if [ -e "$outputdir"/"$output" ]; then
numoutput=$(find "$outputdir"/old_logs -type f -name ""$output"*" | wc -l)
let numoutput="$numoutput"+1
mv "$outputdir"/"$output" "$outputdir"/old_logs/"$output"."$numoutput"
fi
echo "Date,Time,Board Position,Speed,Noncerate [GH/s],Hashrate [GH/s],Good,Errors,SPI-Errors,Miso-Errors" > "$outputdir"/"$output"
for (( i=1; i<="$numboards"; i++)); do
chipout="$outputdir""/chips_board_""$i"
if [ -e "$chipout" ]; then
numchipout=$(find "$outputdir"/old_logs -type f -name ""chips_board_""$i"*" | wc -l)
let numchipout="$numchipout"+1
mv "$chipout" "$outputdir"/old_logs/"$chipout"."$numchipout"
fi
echo "Chip stats for board: ""$i" > "$chipout"
echo "Date,Time,Chip,ProgParams,Speed,Noncerate,Hashrate,Nonces/round,False nonce,SPIerr,MISOerr,Jobs/5min (hash rate),ChipID,CoresOK" >> "$chipout"
done
echo "Starting to log data"
echo "Time to collect data for: ""$logtime"" minutes"
# During the data collection period (set by $logtime) parse data from the logfile to the output files
let countdown="$logtime"*"60"
while [ "$countdown" -ge "0" ]; do
# If timestamp in the log file is the same as the timestamp on the last entry in the output file then sleep for a while
# Should make sure that we're somewhere in the middle of the 5 minute chainminer logging period
# Could use "while" here, but risk getting stuck in a never-ending loop if log file is not being updated
prevtimestamp="none"
if [ -e "$outputdir"/old_logs/"$output"."$numoutput" ]; then
prevtimestamp=$(tail -n 1 "$outputdir"/old_logs/"$output"."$numoutput" | awk -F"," '{print $2}')
fi
if [ "$timestamp" == "$prevtimestamp" ]; then
echo "Chainminer log file not yet updated. Will now sleep for a short while."
echo "Chainminer log file not yet updated. Will now sleep for a short while." >> "$outputdir"/"$output"
sleep 60
timestamp=$(ls --full-time "$logfile" | awk '{print $7}' | awk -F"." '{print $1}')
fi
# Strip board data out of the chainminer log file and copy to the output file
IFS=$'\r\n' datalines=($(grep -A "$numboards" record "$logfile" | tail -n "$numboards" ))
for i in "${datalines[@]}"; do
echo -ne "$datestamp","$timestamp", >> "$outputdir"/"$output"
echo "$i" | tr ":" " " | awk '{$1=$1}1' OFS="," >> "$outputdir"/"$output"
done
# Strip chip data out of the chainminer log file and copy to chip output files (one for each H-board)
for (( i=1; i<="$numboards"; i++)); do
chipout="$outputdir""/chips_board_""$i"
let startline="$i"*"16"-"15"
let endline="$i"*"16"
while read line; do
echo -ne "$datestamp","$timestamp", >> "$chipout"
echo "$line" | awk '{for (i=1; i<=12; i++) printf("%s%s", $(i), i<12 ? OFS="," : "\n"); }' >> "$chipout"
done < <(awk 'NR==v1,NR==v2' v1="${startline}" v2="${endline}" "$logfile")
done
echo "Time remaining: ""$countdown"" seconds"
if [ "$countdown" -gt "0" ]; then
sleep 300
fi
let countdown="$countdown"-"300"
timestamp=$(ls --full-time "$logfile" | awk '{print $7}' | awk -F"." '{print $1}')
done
echo "Finished logging data"
exit 0