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 Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 10:26 AM
Checking cp progress MarGur UNIX for Dummies Questions & Answers 0 05-15-2007 04:13 PM
progress bar sakthi.abdullah UNIX for Advanced & Expert Users 4 12-08-2006 04:23 AM
TAR- Progress bar? dicko44 Shell Programming and Scripting 1 09-01-2006 08:11 AM
progress bar inquirer Shell Programming and Scripting 3 11-26-2002 10:22 PM

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

Join Date: Jan 2008
Posts: 191
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
Sponsored Links
  #2 (permalink)  
Old 05-21-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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 03: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

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 12:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66