#!/bin/sh
# SCRIPT: copyx ver 1.0, 14-9-2011
# PURPOSE: Copies files and shows the progress of copying.
# Usage Example: ./copyx my100gbfiles.tar.gz /path/to/destination/my100gbfiles.tar.gz
copyx()
{
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
| awk '{
cal += $NF
if (cal % 10 == 0) {
percentage = cal / totalsize * 100
printf "%3d%% [", percentage
for (i=0;i<=percentage;i++)
printf "="
printf ">"
for (i=percentage;i<100;i++)
printf " "
printf "]\r"
}
}
END { print "" }' totalsize=$(stat -c '%s' "${1}") cal=0
}
#!/bin/bash
# SCRIPT: mycopy
# PURPOSE: Copies files and shows the progress of copying.
# Usage Example: ./mycopy my100gbfiles.tar.gz /path/to/destination/my100gbfiles.tar.gz
howtouse()
{
echo "=========================================================\n"
echo "Usage Example: $0 my100gbfiles.tar.gz /path/to/destination/my100gbfiles.tar.gz\n"
echo "=========================================================\n"
exit 1;
}
test $# == 2 || howtouse
echo "=========================================================\n"
echo "Preparing to copy\n"
echo "=========================================================\n"
original_file_size=$(stat -c %s $1)
>$2
destination_file_size=0
cp -f $1 $2 &
while [ $original_file_size -gt $destination_file_size ] ; do
destination_file_size=$(stat -c %s $2)
coyp_percentage=$((( 100 * $destination_file_size ) / $original_file_size ))
if [ $pct -lt 10 ] ; then
echo -en "# $coyp_percentage%\b\b\b\b"
else
echo -en "# $coyp_percentage%\b\b\b\b\b"
fi
sleep 1
done
echo
root@server:$ ./xcopy /tmp/redhad.iso /usr/local/src
93% [===============================================> ]
root@server:$ ./xcopy /tmp/redhad.iso /usr/local/src
######################### 15%
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (2)
Commented:
Commented: