LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 05-24-2008, 11:58 PM   #1
wrapster
Member
 
Registered: May 2008
Posts: 155

Rep: Reputation: 30
why is this cp script not working properly?, help needed, pls!!


Hi all,

I am trying to include a percentage bar with the cp command...
basically i am copying a few files onto ram during the boot process itself...
these files come upto 550mb and it evidently takes up some time for the cp to happen....
I have written a script that calculates the % of completion but the problem is that am unable to see the numericals when the cp is underway..
All i can see is the % mark that keeps moving...

But here is the surprising thing...If i use the same script to cp files once the system is up and running, i can see the numericals as well...
I am not sure why this is happening and need your help in figuring it out!!

Here is the code
#!/bin/sh

copy()
{
if [ $# = 2 ];then
source=`/usr/bin/stat -c %s $1`
dest=0
while [ $source -gt $dest ];do
dest=`/usr/bin/stat -c %s $2`
/usr/bin/cp -f $1 $2 &
#echo "# \c"
pct=`/usr/bin/expr $dest*100`
pct1=`/usr/bin/expr $pct/$source | /usr/bin/bc`
echo "$pct1% \c"
dest=`expr $dest+1`
sleep 1
done
else
echo "error"
fi
}

echo "now starting"
copy <file1> <file2>

The doubt i had was where the bc was capable of running at boot time?
So i included the binaries of bc into the ramdisk....but even then thre is no change??
Could you pls help me out with this?

NOTE:remember that this function is included in the one of the scripts that is required to mount FS onto respective place.....its not used after the system is up and running!!!!

Thanks
 
Old 05-25-2008, 03:06 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Not directly answering to you question but there is a flaw in your script. If cp hasn't complete in less than one second, you start a new cp from the beginning while the older one is still running. The cp command should be placed outside the while loop.
 
Old 05-25-2008, 07:20 AM   #3
wrapster
Member
 
Registered: May 2008
Posts: 155

Original Poster
Rep: Reputation: 30
oh!!!! ok,
guess my logic was wrong...
I will place the cp outside the loop and rm sleep, lets see what happens...
Will reply back!!

Thanks
 
Old 05-25-2008, 08:44 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Ouch. Don't remove the sleep unless you want to hog your box ...
 
Old 05-25-2008, 10:31 AM   #5
wrapster
Member
 
Registered: May 2008
Posts: 155

Original Poster
Rep: Reputation: 30
well well well!!!!!
guess i found it out for myself....

Thanks anyway, but i have a even bigger problem now, infact a major one...
Pls read my next post and help me out ...

Thanks
 
Old 05-26-2008, 12:15 AM   #6
wrapster
Member
 
Registered: May 2008
Posts: 155

Original Poster
Rep: Reputation: 30
Hi there is a big flaw in the script as i found out.....
all the while i had been testing with some big files by transferring it from one point to another within the HD, so i it was pretty fast and the %shown was within a single line...
To test from the cd itself, i ran this script and passed arg,to cp frm the cd to HD and have a look at what i got...

now starting
0% 0% 0% 0% 0% 1% 2% 2% 3% 4% 4% 5% 6% 6% 7% 8% 8% 9% 10% 10% 11% 12% 13% 13% 14% 15% 16% 16% 17% 18% 19% 19% 20% 21% 22% 23% 23% 24% 25% 26% 27% 27% 28% 29% 30% 31% 31% 32% 33% 34% 35% 36% 36% 37% 38% 39% 40% 41% 42% 43% 43% 44% 45% 46% 47% 48% 49% 50% 51% 52% 53% 54% 54% 55% 56% 57% 58% 59% 60% 61% 62% 63% 64% 65% 66% 67% 68% 69% 70% 71% 72% 73% 74% 75% 76% 77% 78% 79% 80% 81% 83% 84% 85% 86% 87% 88% 89% 90% 91% 92% 93% 94% 96% 97% 98% 99% 100% bash-3.2#

This is neither professional nor is it good looking
may i know how i can have it at a single point ,like the way it generally happens with other cp.....
do i need to have a for loop?

Thanks
 
Old 05-26-2008, 01:43 AM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Please explain better what differs when the script doesn't display the wanted output and post your current script code too.
 
Old 05-26-2008, 02:20 AM   #8
wrapster
Member
 
Registered: May 2008
Posts: 155

Original Poster
Rep: Reputation: 30
I meant,
the code that i have already posted, gave me the %status like the one ive shown...
this means,in the boot screen this many lines are displayed,which is aesthetically not right!!!
I wanted to know how i can display from 1-100% on a single spot,thats all...
I mean instead of those lines, how do i get 1% then 2% instead of 1 (as the cp progresses)so on upto 100...which would look nice!!

Thanks
 
Old 05-26-2008, 03:47 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
I wasn't asking that much about what differs in the output which is obvious but really what differs in the way you launch the script. You do not tell how and where you run it.

Anyway, you can try replacing the non portable

Code:
echo "$pct1% \c"
by

Code:
printf '%d%%\r' $pct1
 
  


Reply



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
awk script help pls cmontr Programming 5 10-24-2007 10:49 PM
Backup shell script not working properly jamespetts Linux - Networking 2 07-15-2006 11:03 AM
Firewall seems configured properly, but still can't open ports needed jslmg Linux - Networking 4 07-13-2004 11:08 AM
pls pls pls help me ! i'm tired with httpd config on fedora apache 2.0.48 AngelOfTheDamn Fedora 0 01-24-2004 05:12 PM
Pls help me write script to shutdown pc Alfastation Linux - Newbie 8 11-10-2003 09:39 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 12:28 PM.

Main Menu
Advertisement
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
Twitter: @linuxquestions
Open Source Consulting | Domain Registration