Skip to content

Instantly share code, notes, and snippets.

@bugcy013
Forked from codingtony/transferMeter.sh
Created May 11, 2014 18:08
Show Gist options
  • Select an option

  • Save bugcy013/761250cd02b900a54ea0 to your computer and use it in GitHub Desktop.

Select an option

Save bugcy013/761250cd02b900a54ea0 to your computer and use it in GitHub Desktop.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment