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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I do a short delay (milliseconds) in a shell script?
# 1  
Old 08-24-2011
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 switch to a different shell if it helps to find a command that will do the delay.
# 2  
Old 08-24-2011
Will this work for you:
Code:
typeset -i mCnt=0
while [[ ${mCnt} -le 1000 ]]; do
  mCnt=${mCnt}+1
done

You can change the number according to your CPU speed.
# 3  
Old 08-24-2011
GNU sleep can take a number like
Code:
sleep 0.1

to sleep a fraction of a second. And since you have BASH, you're probably on a GNU/Linux system.

This has nothing to do with what shell you use, since sleep is an external utility.
# 4  
Old 08-24-2011
it will slowing down for few millisecond.
Code:
sleep 0

in perl try
Code:
perl -e 'select(undef,undef,undef,.1)'

# 5  
Old 08-24-2011
I tried the "sleep 0.1" suggestion, but it says "sleep: bad character in argument".

It seems like the other suggestions are "doing it the hard way" in terms of forcing the script to do a lot of other processing to in effect slow it down. But if there's no better way to do a small delay then I'll have to resort to that.
# 6  
Old 08-24-2011
Quote:
Originally Posted by harmlesscat
I tried the "sleep 0.1" suggestion, but it says "sleep: bad character in argument".

It seems like the other suggestions are "doing it the hard way" in terms of forcing the script to do a lot of other processing to in effect slow it down. But if there's no better way to do a small delay then I'll have to resort to that.
Is it possible that you have 2 different sleeps-- a builtin and a binary? Perhaps see if /bin/sleep (or some other appropriate location...) can be called directly.
# 7  
Old 08-24-2011
Quote:
Originally Posted by Corona688
GNU sleep can take a number like
Code:
sleep 0.1

to sleep a fraction of a second. And since you have BASH, you're probably on a GNU/Linux system.

This has nothing to do with what shell you use, since sleep is an external utility.
Actually, ksh has a built-in sleep which accepts a fractional argument. If the OP has ksh on his system, it may be an expedient solution.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I am learning shell scripting and i would like to understand how sort -k3,3 -k 4,4 short* works

Please help me understand how sort -k3,3 -k 4,4 short* works , is it sorting 3 and 4 th field ? what is the use of specifying 3,3 and 4,4 in sort and what is actually does and i see sort -k3 short* and sort -k3,3 -k 4,4 short* giving the same output. Sort output attached Please help (2 Replies)
Discussion started by: Antony Ankrose
2 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. OS X (Apple)

Shell Script to change desktop short cut Icon

I have installed my flash application using shell script. I have created short cut to desktop. Now i want to change the default short cut Icon. Please tell me script to change the short cut icon. ---------- Post updated at 12:54 AM ---------- Previous update was at 12:33 AM ---------- Working... (0 Replies)
Discussion started by: rohaneee
0 Replies

4. 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

5. 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

6. UNIX Desktop Questions & Answers

Script that will display a short message

Can anyone point me to the right direction on how to write a simple script that will display a message on any terminal when implemented? Basically I need it so the script runs at a certain time, say April 30, 2010 and that the message will be displayed to me no matter which terminal I am logged... (2 Replies)
Discussion started by: jmack123
2 Replies

7. 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

8. Shell Programming and Scripting

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... (10 Replies)
Discussion started by: wrapster
10 Replies

9. Shell Programming and Scripting

short script help

how do i find out the date of the last time the system was last booted from? (8 Replies)
Discussion started by: jodders
8 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