2
0
I have the following code as part of a shell script:
while [ $(ps -ef | awk '{print $2}' | grep -F "$CPPID") ]; do
sleep 10
awk -v "usbsize=$(/bin/df | grep -F $DEVICEMOUNTPOINTQ | awk '{print $3}')" -v "isosize=$(/bin/df | grep -F $ISOMOUNTPOINTQ | awk '{print $3}')" 'BEGIN { printf "%.1f", 100 * usbsize / isosize }' && echo "% copied..."
done
This is monitoring cp
doing the following operation:
cp -a "$ISOMOUNTPOINT"/* "$DEVICEMOUNTPOINT"
And this works fine for the most part, until
90.5% copied...
94.2% copied...
97.8% copied...
101.6% copied...
102.7% copied...
Why does this exceed 100% of the size of the source? The copy is from a loop-mounted ISO to a NTFS-formatted partition on a USB flash drive. I'm guessing this is probably a filesystem thing?
What is my example missing to make the sizes match up, so that when cp
completes it is 100% copied, not 103%?
Thanks.
Re: Bounty
I will award the bounty to the first person to produce a solution similar to the above code that meets the following criteria:
- The script must be able to detect copying at a 1:1 ratio
- The script must not display a value in excess of 100% copied, however...
- The script must not simply cap the display at 100% copied when it exceeds it.
If the data size does indeed differ from source to destination for some reason, then I'd like a script that notices this and still displays the actual ratio copied.
its unclear of what you want in the end: just copy files via commandline and give progress? how does that relate to the title of your question? – akira – 2011-01-31T17:00:56.520
I have a working setup which already gives the progress, however it exceeds 100% copied. I want to know why that is, and how to reach one of the goals specified at the end. – Matthieu Cartier – 2011-01-31T17:02:12.033