bueller.ca

the digital workshop of Matt Ferris

crononce

Language(s)
Bash
Requirements
Linix/UNIX/BSD

crononce is a utility that allows you to schedule one-off tasks without the use of cron.

Synopsis

crononce dir

Description

crononce scans dir for files matching the current timestamp (formatted as yyyymmddhhmm). If a matching file is found, crononce attempts to execute the file. After execution the file is deleted.

When sheduled to run from cron, crononce allows you to schedule an event to take place one time only. Such events may be the scheduled restart of a service or one-time backup of files. Alternatively, you could schedule the event through cron and then setup a reminder for yourself to remove the event from the crontab before cron ran the event again.

In the case where a service needed to be restarted at 12:30am, you need only write a shell script with the appropriate command(s), name it according to the date and time it will need to run (for April 5th, 2010, the filename would be 201004050030) and place it in dir. crononce (if scheduled from cron) will see the file, execute it and restart the service for you. Because it also deletes the file once it's done executing, it ensures the service will only be restarted once.

If you have two or more events that need to be scheduled at the same time you can either create one script to execute all the events, or create separate scripts for each, appending some unique identifier to the end of the filenames. crononce matches all files starting with the timestamp.

For events that take place often but aren't appropriate for a cron job (such as events that take place at irregular intervals), you can script the event but store the script somewhere other than dir. When you want to schedule the event, simply create an appropriately named symlink in dir and crononce will remove the symlink and not the actual script, removing the need to rewrite the script each time.

Options

Configuration

Ideally, crononce will be scheduled in cron to run every minute:

*/1 * * * * /usr/bin/crononce /etc/crononce

Comments