how to introduce delay in the script??(urgent)

Hi all,

i would like to know how to introduce a delay in the execution of a cmd?

am trying to copy a file which is about 650 mb and then perform some actions on it..
however since its huge i would like to introduce a delay in exection until the process is over

i dont want it to proceed to next statement unless this is over..

if [$? -eq 0] then
<do somethng>
else
<give error>
fi

this is the script that had included after the cp statement but am always directed to the else part of the loop :frowning:

other thing i tried was to introduce a wait statemnt..
but there is already another process that is to be run in BG ,so when i use $! it refers to that old process(i hope!!).

so is there a way to address many bg process, also anyway to capture the pid of the particular process i need..

Hence i would like to know how to introduce a delay in the script..
This is not a regular script , its a rc script!!!

pls advice accordingly

there is a command called
sleep

do a man sleep

yes i know about it..
But the problem is i need to specify the exact amount of sec that it takes for the command to execute..
caclulating it will be difficult..

so its difficult to specify the exact time ,i need to use the sleep for..

I'm not quite clear on something. First you said

Then you said

So I'm a little confused. At any rate, you specify the number of seconds you want the cmd to sleep. For example:

sleep 300   # sleep for 300 seconds, or 5 minutes

Don't put it in the background. The next statement won't start until the first statement is finished.

If you really must put a bunch of programs in the background and wait for one to finish, then you need to save each pid and then wait for the one you want:
process1 &
pid1=$!
process2 &
pid2=$!

wait $pid1

Hi,

This is in response to matt.d's que..

I said i needed a "sleep" to prevent further exe of statements unless the first one is complete..
now the first statement is a cp statement and tis copying 650 mb file..
so this process is system dependent, as in the processor speed and such issues..
so its difficult to specify the actual time i want to exe the sleep cmd!!!

If i specify on generic terms then ,it might waste the cpu time and increase latency...

Got my point???

Hi,

You can proceed as follow:

cp /home/yogi /home/wrapstar

copy()
{

a= /home/yogi |wc -l
b=/home/wrapstar |wc-l
}

proceed()
{
if [ $a -gt $b ]
then
echo "still copying"
copy
else
echo " Copying is completed"
fi
}

Hopefully this code will work for you. This will echo a message "still copying" till the cp process finshes. And next command will only be executed if copy process completes.

Thanks-
Yogi

Oh thanks a lot,
this will definitely help me,
i will surely get back to you regarding the output...

Thanks again:b:

hi ,
can you just explain the script..
because ,we know that the shell automatically inserts a wait call, if the preceeding process isnt complete..
in which case, that cp /home/wrap /home/xyz will have to first be completed before entering the copy(),
isnt it??

Why do you need to further check?(to introduce a delay)
do you have any other idea?

Shouldn't we be asking you these kinds of questions?

Either you want the copy to run in the background (you'll need a trivial mod to yogi's example) or you don't, in which case you are already waiting until it finishes. Is neither of these what you want? Then could you explain some more?

You have mixed everything up...the first advise you were given is to use sleep command but as per your response that this depends on file size and CPU speed,...etc.....then a script was provided and again you said this will not work....for both cases, i have one question for you, now you want to copy the file then execute the next command, now by logic the next command won't be executed unless the copy is finished, so where are you lost exactly because it doesn't seem for me that you have a problem, the script will automatically not execute the next exe unless the copy is finished...so where is the PROBLEM??