bugcy013
5/11/2014 - 6:08 PM

transferMeter.sh

#!/bin/bash -e

# Little program that measure the speed in MBps of a file transfer occuring in the current directory

LASTTIME=$(date +%s)
LASTSIZE=$(du -bs . 2> /dev/null | awk '{ print $1 }')
TOTALSIZE=0
TOTALTIME=0

while true
do
        TIME=$(date +%s)
        SIZE=$(du -bs . 2> /dev/null | awk '{ print $1 }')
        ELAPSED=$((${TIME}-${LASTTIME}))
        SIZECHANGE=$((${SIZE}-${LASTSIZE}))
        TOTALSIZE=$((${TOTALSIZE}+${SIZECHANGE}))
        TOTALTIME=$((${TOTALTIME} + ${ELAPSED}))
        echo | awk -v tsz=${TOTALSIZE} -v tt=${TOTALTIME} '{ if (tt > 0) { printf "%.2f MBps\n", tsz/1024/1024/tt } }'
        LASTSIZE=${SIZE}
        LASTTIME=${TIME}
        sleep 2
done