The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Progress mirusnet Shell Programming and Scripting 2 01-21-2008 08:26 AM
Checking cp progress MarGur UNIX for Dummies Questions & Answers 0 05-15-2007 01:13 PM
progress bar sakthi.abdullah UNIX for Advanced & Expert Users 4 12-08-2006 02:23 AM
TAR- Progress bar? dicko44 Shell Programming and Scripting 1 09-01-2006 05:11 AM
progress bar inquirer Shell Programming and Scripting 3 11-26-2002 08:22 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-20-2008
Registered User
 

Join Date: Jan 2008
Posts: 183
how to have a cp progress bar?

Hi all,
This is a reformed post to my earlier ones!!!!!!

I would like to know how to include a progress bar while using the cp...
I am copying a few huge files from cdrom but am unable to figure out ,how to give a progress bar!!!!!

I checked out other sites as well,but the issue here is that,this cp is happenning in one of the boot scripts during boot time!!!

So i cannot have other explicit executable scripts that run within an already running script, also i tried converting some script to functions and passing these files as args,but didnt work!!!!

So could you pls give out some scripts (plain scripts) that do the job?

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 05-20-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Here's a quick hack. If you don't have awk or stat available, I don't imagine you will have Perl, either.

Code:
#!/bin/sh
#
# cpbar -- era 2008-05-21 for unix.com
#
# Depends:
#  stat
#  cp
#  awk

syntax () {
    echo "Syntax: $0 srcfile destfile" >&2
    echo " " "$@" >&2
    exit 1
}

test -r "$1" || syntax "File '$1' not found"
test -d "$2" && syntax "Must name destination file ('$2' is a directory)"

size=`stat -c %s "$1"`

cp "$1" "$2" &
cppid=$!

trap 'echo; kill $cppid; rm -f "$2"; exit 127' 1 2 3 5 15

while true; do
    nsize=`stat -c %s "$2"`
    awk -v f1="$1" -v f2="$2" -v size=$size -v nsize=$nsize '
	BEGIN { printf "Copying %s to %s: %4.2f%%\r", f1, f2, 100*nsize/size }'
    case $nsize in $size) break ;; esac
    sleep 1
done

echo

wait $cppid

Last edited by era; 05-21-2008 at 12:00 AM. Reason: Remove destination file if interrupted; percentage calculation wrong (duh :-); put break after awk so it prints 100% at end
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0