home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 40.1 Off-Peak Job Submission Chapter 40
Delayed Execution
Next: 40.3 The at Command
 

40.2 Waiting a Little While: sleep

sleep
sleep
The sleep command waits. That's all it does. (GNU versions are usually loaded with features, but the sleep on the disc doesn't do more than the standard version.) So, what good is it?
  • A quick-and-dirty reminder service when you don't have leave (48.5 ) . This will print the message Time to go now.... in 10 minutes (600 seconds):

    ( ) &
     ;
     
    % (sleep 600; echo Time to go now....) &
    
    

  • You can't use at (40.3 ) and you have to run a job later (say, three hours):

    % (sleep 10800; someprog) &
    
    

  • To watch a program (usually a shell script) that's running in the background and see what processes it runs:

    
    
    
    
    
    
    
    !!
     
    
    
    
    
    
    % prog
    
     &
    [1] 12345
    % sleep 5;ps
    
    
      PID TT STAT  TIME COMMAND
    18305 p4 S     0:01 -csh (csh)
    18435 p4 S     0:00 /bin/sh prog
    18437 p4 D     0:00 /bin/sort -r temp
    18438 p4 R     0:00 ps
    % !!;!!;!!;!!;!!
    
    
    sleep 5; ps; sleep 5; ps; sleep 5; ps; sleep 5; ps; sleep 5; ps
      PID TT STAT  TIME COMMAND
        ...
        ...5 seconds pass...
    
      PID TT STAT  TIME COMMAND
        ...

  • When you're running a series of commands that could swamp the computer, give it time to catch up. For instance, the mail (1.33 ) program starts background processes to deliver the mail. If you're sending a bunch of form letters, sleep five or ten seconds after each one:

    foreach
     
    
    
    % foreach name (`cat people`)
    
    
    ? formltrprog $name | mail $name
    
    
    ? sleep 10
    
    
    ? end
    
    

    Or, to send print jobs while you're at lunch - but give other people a chance to print between yours:

    % lp bigfile1;sleep 600;lp bigfile2;sleep 600;lp bigfile3
    
    

- JP


Previous: 40.1 Off-Peak Job Submission UNIX Power Tools Next: 40.3 The at Command
40.1 Off-Peak Job Submission Book Index 40.3 The at Command

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System