LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Thread Tools
Old 07-27-2009, 07:43 PM   #16
surfreak
LQ Newbie
 
Registered: May 2009
Posts: 4
Thanked: 0

[Log in to get rid of this advertisement]
Found this, anyone want to decode it a bit?

From http://chris-lamb.co.uk/2008/01/24/c...bar-like-wget/ (safe)



#!/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
}
surfreak is offline     Reply With Quote
Old 10-02-2009, 02:54 PM   #17
Hackeron
LQ Newbie
 
Registered: Oct 2003
Posts: 16
Thanked: 0
Question

I generally use rsync -aP to copy to see a progress, but it shows a progress on a per file basis and a file count.

Is there anything that will show the overall progress based on size left to copy?
macos Hackeron is offline     Reply With Quote
Old 11-07-2009, 02:02 AM   #18
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,026
Thanked: 4
Quote:
Originally Posted by homey View Post
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>.

Last edited by frenchn00b; 11-07-2009 at 02:10 AM..
linuxdebian frenchn00b is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cp with progress bar? Rotwang Linux - General 5 04-27-2005 08:49 PM
CLI progress bar for mv and cp command??? Lleb_KCir Linux - General 4 03-12-2005 10:12 PM
Progress bar image craigs1987 Fedora 0 05-27-2004 03:31 PM
cp: progress bar chii-chan Linux - General 2 10-30-2003 07:30 PM
Progress Bar zael Programming 3 10-01-2003 01:20 PM


All times are GMT -5. The time now is 07:55 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration