[NetBehaviour] a non art object

James Morris james at jwm-art.net
Fri Jul 24 01:25:44 CEST 2015


#!/bin/bash

# cppc.sh
#
# script to measure the in-progress progression of data as it
# is copied from one partition to another
#
# script determines this by being passing two paths as arguments:
# the first path is on the source partition
# the second path is on the destination partition
#
# assumptions:
# * the copying is in progress
# * the source partition is being copied in its entirity
# * the destination partition was empty when copying began
# * usedness of the source partition is unchanging
#
# notes:
# * values fluctuate wildy before settling
# * values are estimates only
# * see end of file for output example
# * this script is non-reliable

function usage
{
echo usage:
echo $0 "[path-on-src-part] [path-on-dest-part]"
exit -1
}

if [[ -z "$1" ]]; then
usage
fi

if [[ -z "$2" ]]; then
usage
fi

TS0=$(date +"%s")
SRC0=$(df --output=used "$1" | tail -n1)
DEST0=$(df --output=used "$2" | tail -n1)
TOTSECS="0"

while true
do
sleep 1
DEST1=$(df --output=used "$2" | tail -n1)
PC=$(echo "($DEST1 / $SRC0) * 100" | bc -l)
TS1=$(date +"%s")
TICK=$(echo "$TS1 - $TS0" | bc -l)
DELTA=$(echo "$DEST1 - $DEST0" | bc -l)
AVG=$(echo "$DELTA / $TICK" | bc -l)
REM=$(echo "$SRC0 - $DEST1" | bc -l)
SECS=$(echo "$REM / $AVG" | bc)
TOTSECS=$(($TOTSECS + $SECS))
AVGSECS=$(echo "$TOTSECS / $TICK" | bc -l)
TIMEREM=$(date -u -d @"$AVGSECS" +"%T")
echo "${PC%%.*}% done, time remaining: $TIMEREM"
done

exit

usage example:

$ ./cppc.sh /home /mnt/parts/sdb1

53% done, time remaining: 01:16:04
53% done, time remaining: 01:16:04
53% done, time remaining: 01:16:03
53% done, time remaining: 01:16:03
53% done, time remaining: 01:16:02
53% done, time remaining: 01:16:02
53% done, time remaining: 01:16:02
53% done, time remaining: 01:16:02
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:00
53% done, time remaining: 01:16:00
53% done, time remaining: 01:16:00
53% done, time remaining: 01:16:00
53% done, time remaining: 01:16:00
53% done, time remaining: 01:16:00
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:01
53% done, time remaining: 01:16:02
53% done, time remaining: 01:16:02
53% done, time remaining: 01:16:02
53% done, time remaining: 01:16:03
53% done, time remaining: 01:16:03
53% done, time remaining: 01:16:03
53% done, time remaining: 01:16:04
53% done, time remaining: 01:16:04
53% done, time remaining: 01:16:05
53% done, time remaining: 01:16:05
53% done, time remaining: 01:16:06
53% done, time remaining: 01:16:06
53% done, time remaining: 01:16:07



More information about the NetBehaviour mailing list