Skip to content

Instantly share code, notes, and snippets.

@codingtony
Last active December 11, 2015 10:48
Show Gist options
  • Save codingtony/4588970 to your computer and use it in GitHub Desktop.
Save codingtony/4588970 to your computer and use it in GitHub Desktop.
Little program that measure the speed in megabytes per second of a file transfer occurring in the current directory
#!/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