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


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 40.7 Making Your at Jobs Quiet Chapter 40
Delayed Execution
Next: 40.9 Checking and Removing Jobs
 

40.8 Automatically Restarting at Jobs

In some situations, it's convenient to create jobs that do their work, finish, and automatically reschedule themselves at some time in the future. Here's how to do this:

#!/bin/sh
myself=/home/mikel/bin/restarter
# Add any commands you want to do real work here
...
sleep 60
at -s 0123 tomorrow $myself

Once you've started this script, it will run every day at 1:23 a.m. The sleep ( 40.2 ) makes sure that the following at command is executed after 1:23 a.m.; this guarantees that the next job will run at 1:23 a.m. tomorrow instead of 1:23 a.m. today. This trick isn't needed on most versions of at , but it isn't a bad idea.

Note that self-restarting jobs really are an artifact of an earlier era, when mortal users were supposed to stay away from the cron ( 40.12 ) facility. Now that users can have personal crontab files, the need for self-restarting jobs should diminish.

If you find that you do need to create scripts that reschedule themselves, please make sure to clean up after yourself! When your program is no longer needed, remember to delete it with atq and atrm ( 40.9 ) .

- ML


Previous: 40.7 Making Your at Jobs Quiet UNIX Power Tools Next: 40.9 Checking and Removing Jobs
40.7 Making Your at Jobs Quiet Book Index 40.9 Checking and Removing Jobs

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