![]() |
|
|
google unix.com
|
|||||||
| Forums | Casino | Register | Forum Rules | Links | Albums | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 |
| Sponsored Links |
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |
![]() |
| Bookmarks |
| Tags |
| None |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|