Quote:
Originally Posted by homey
Here's another sample which maybe abit more usefull.
Code:
#!/bin/bash
# File copy with progress indicators
# Example: ./test original_file destination_file
usage()
{
echo "Usage: $0 original_file destination_file"
exit 1;
}
test $# == 2 || usage
echo Preparing to copy
orig_size=$(stat -c %s $1)
>$2
dest_size=0
cp -f $1 $2 &
while [ $orig_size -gt $dest_size ] ; do
dest_size=$(stat -c %s $2)
pct=$((( 100 * $dest_size ) / $orig_size ))
if [ $pct -lt 10 ] ; then
echo -en "# $pct%\b\b\b\b"
else
echo -en "# $pct%\b\b\b\b\b"
fi
sleep 1
done
echo
And here is another....
Code:
#!/bin/bash
# Example: ./test original_file destination_file
usage()
{
echo "Usage: $0 original_file destination_file"
exit 1;
}
test $# == 2 || usage
orig_size=$(stat -c %s $1)
>$2
dest_size=0
cp -f $1 $2 &
while [ $orig_size -gt $dest_size ] ; do
dest_size=$(stat -c %s $2)
pct=$((( 69 * $dest_size ) / $orig_size ))
echo -en "\r["
for j in `seq 1 $pct`; do
echo -n "="
done
echo -n ">"
for j in `seq $pct 68`; do
echo -n "."
done
echo -n "] "
echo -n $((( 100 * $pct ) / 69 ))
echo -n "%"
done
echo
|
those results. Could they be in official Debian packages?
that's just a tar.gz to make, and send a file chmoded to :
/usr/bin/ such as hcp
or progressbarcp
It would be could to be in the repositories
or the very best would be to be into cp itself
such as
Code:
cp -p file.ext target.ext
with -p for progress bar added
Damn right you can.
Quote:
#!/bin/sh
cp_p()
{
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
| awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%3d%% [", percent
for (i=0;i<=percent;i++)
printf "="
printf ">"
for (i=percent;i<100;i++)
printf " "
printf "]\r"
}
}
END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}
|
In action:
Quote:
% cp_p /mnt/raid/pub/iso/debian/debian-2.2r4potato-i386-netinst.iso /dev/null
76% [===========================================> ]
|
the not good part 30 to 50pct:
Quote:
Be aware, however, that this adds quite some overhead (30% to 50% in my tests) to the time needed to copy a file. A probably better way would be to use <code>dd</code> under the hood and get its progress status by <code>kill -USR1 $PID</code>. You lose all switches that <code>cp</code> understands, however.
In the end it would probably be better to add a switch to <code>p</code>.
|