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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to introduce delay in the script??(urgent)
# 1  
Old 03-23-2008
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 Smilie

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
# 2  
Old 03-23-2008
there is a command called
sleep

do a man sleep
# 3  
Old 03-23-2008
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..
# 4  
Old 03-23-2008
I'm not quite clear on something. First you said

Quote:
Originally Posted by wrapster
i need to specify the exact amount of sec that it takes for the command to execute..
Then you said

Quote:
so its difficult to specify the exact time ,i need to use the sleep for..
So I'm a little confused. At any rate, you specify the number of seconds you want the cmd to sleep. For example:

Code:
sleep 300   # sleep for 300 seconds, or 5 minutes

# 5  
Old 03-23-2008
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
# 6  
Old 03-24-2008
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???
# 7  
Old 03-24-2008
MySQL

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

Last edited by bisla.yogender; 03-24-2008 at 11:06 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. Shell Programming and Scripting

Delay in running script from crontab

I am facing an issue where sometimes crontab is running script with some delay. Below is the stmt in script and it is the only stmt in script. echo "running at `date` " >> CRONCHECK.log Below is the cron entry. 0 11 * * * CRONCHECK.sh Below is the time of run each day. running at Fri... (8 Replies)
Discussion started by: Nishant Singh
8 Replies

3. UNIX for Dummies Questions & Answers

Is it possible to introduce a character using sed?

I need to reformat a text using sed command like Text: 160845 Output: 16:08:45 Please help me how this can be done using sed. Thanks in adv (1 Reply)
Discussion started by: siteregsam
1 Replies

4. Solaris

Create files to introduce with ZFS

Hello, To learn ZFS, i try to create pool . and for that i want create 10 files with 512MB (because i dont have multiple disks and multiple controllers) ADMIT THAT THIS IS TEN HIGH-PERFORMANCE HARD DRIVES To get this 10 files,all of them have the same size : 512MB, I do these... (9 Replies)
Discussion started by: herbich1985
9 Replies

5. Shell Programming and Scripting

How do I do a short delay (milliseconds) in a shell script?

I need to put a small delay into a shell script. I'm looking for something smaller than "sleep" - a second is way too long. I want to sleep something like 10 milliseconds. I've tried "usleep" and "nanosleep", but the script doesn't recognize them. I'm using the bash shell but I'm willing to... (9 Replies)
Discussion started by: harmlesscat
9 Replies

6. Shell Programming and Scripting

How to introduce delay in Shell Script till a key stroke.

Hi All, How to introduce delay in the Bash/Shell Script till key stroke. Below is the requirement.. 1.Execute set of commands. 2.Display the message echo "press any key to continue" Introduce a delay till key stroke. 3.Execute next set of commands. Thanks in Advance Sunil.K (5 Replies)
Discussion started by: sunilrk07
5 Replies

7. Shell Programming and Scripting

Want to have delay in multiple instances of the same shell script

Hello, My goal is to run the same Shell script in a parallel mode. This script will get triggered from different machines and different application teams by some job scheduling tool. They may trigger the process at the same time. so I want to have them in QUEUE ..and release them for execution on... (3 Replies)
Discussion started by: chetan_sonar
3 Replies

8. UNIX for Dummies Questions & Answers

Let my introduce myself and one doubt!!!!

Hello, My name is John. I am from Spain and I am learning Linux and how to use it. I hope to learn more in this forum. I am developing a new application, and I have a doubt: Can I read a file, line by line, in C programm? Best regards. (1 Reply)
Discussion started by: webquinty
1 Replies

9. Shell Programming and Scripting

adding delay in script

Hi Expert, I need to run some command 5 times with 5 mins interval whenever one of the application on server hang. Can I use below scripts ? Thanks! ------------- #!/bin/sh command1 sleep 300 command2 sleep 300 command3 sleep 300 command4 sleep 300 command5 sleep 300... (2 Replies)
Discussion started by: skully
2 Replies

10. UNIX for Dummies Questions & Answers

Insert a delay in a script

Hi all, i need help. I want to write a script and insert a delay time of 10 seconds. Which is the command for do this? Thanks in advance (1 Reply)
Discussion started by: christian
1 Replies
Login or Register to Ask a Question