The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
handling Infinite fork ashish_uiit UNIX for Advanced & Expert Users 3 05-21-2008 02:22 AM
the given code goes in infinite loop and does not increment variable i mrityunjay22 Shell Programming and Scripting 6 12-26-2007 02:20 AM
pick the bug the server enters an infinite loop arjunjag High Level Programming 3 07-19-2007 01:53 AM
ls command in infinite Loop umakant SUN Solaris 3 07-17-2007 01:25 AM
high priority thread contains an infinite loop rvan High Level Programming 0 02-14-2007 09:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-20-2008
ashish_uiit ashish_uiit is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 25
Which is more efficient - sleep or infinite while?

Hi
i need to make a script to check disk space every hour.

****Note that cron is not allowed.

So i need to use either sleep or while 1 ...pls suggest which is more efficient in this scenario?

And is there any other way to do the task?

Thanks,
Ashish
  #2 (permalink)  
Old 08-20-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
The most efficient and simple way is while and sleep.

Code:
while [ 1 ]
do
    your_stuff...
    sleep 3600
done
  #3 (permalink)  
Old 08-20-2008
ashish_uiit ashish_uiit is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 25
Quote:
Originally Posted by redoubtable View Post
The most efficient and simple way is while and sleep.

Code:
while [ 1 ]
do
    your_stuff...
    sleep 3600
done
Hi thanks for reply ..
if i use sleep with goto ..will that be moe effiecient as comapred to while 1?

Also what are drawbacks of sleep and while 1.
  #4 (permalink)  
Old 08-20-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
I would say that's pretty much the same thing (while and goto) but for the sake of simplicity I would advise you go use while.

There are no drawbacks in sleep and while 1. It does it's job and then simply does nothing for 3600 seconds.
  #5 (permalink)  
Old 08-21-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
actaully, as i have recently learned, [ 1 ] is not the best way

Code:
while :
do
     some stuff
     sleep 11101
done
  #6 (permalink)  
Old 08-21-2008
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Quote:
Originally Posted by broli View Post
actaully, as i have recently learned, [ 1 ] is not the best way

Code:
while :
do
     some stuff
     sleep 11101
done
I always use
while : ; do
myself and I would never use
while [ 1 ] ; do
but I wonder why you object to it. I object to it because it is a terribly misleading construct:
Code:
$ [ 1 ] && echo yes
yes
$ [ 0 ] && echo yes
yes
$ [ xyzzy ] && echo yes
yes
$
Few people expect all 3 of those to behave the same. But assuming that : and [ are both shell built-in commands, they should be about as fast.
  #7 (permalink)  
Old 08-21-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
Quote:
Originally Posted by Perderabo View Post
but I wonder why you object to it. I object to it because it is a terribly misleading construct
well, [ 1 ] implies the shell executes all the code for the builtin test
as i undestand it, the ":" is more closer to null code...
yes, both are built in, but im sure [ has tons of lines to work as the external test (and all the testing capabilitie it has)
: "looks & feels slimer"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0