[dev] A simple but flexible alternative to cron

From: Eric Pruitt <eric.pruitt_AT_gmail.com>
Date: Fri, 6 Feb 2015 23:30:56 -0800

I've wanted something with a bit more flexibility than standard Cron for
a while, and I finally came up with a simple solution that I like and
felt might be of interest to this community.

The core of my scheduler is a Bash script, and the script searches for
files in a "tasks" subfolder that has one folder for each hostname the
scheduler is run on. Here's what the layout of what I currently have
looks like:

    cron$ tree
    .
    |-- cron
    |-- logs
    | `-- [...]
    `-- tasks
        `-- sinister
            |-- backup.sh
            |-- email-digest.sh
            `-- woot-watch.sh

Each of the scripts has two functions defined: "condition," which exits
successfully if the script should run and "run," which contains the
execution logic. The core script sources each of the tasks for the
current host then checks to see if the "condition" function exits
successfully before invoking the "run" function and logging the output.

I currently run the core scheduler on top of top Vixie / ISC cron so I
don't have to worry privileged system access:

    ~$ /usr/bin/crontab -l
    MAILTO=""
    * * * * * bash ~/cron/cron

I've attached the prototype I'm currently using to this email as well as
a sample task script. I know Bash isn't considered suckless, but there's
nothing preventing any of this from being done in POSIX shell. The
script also recognizes "-l" and "-e" flags for listing and editing
scripts, respectively, and I currently have the core script symlinked to
~/bin/crontab.

Eric

Received on Sat Feb 07 2015 - 08:30:56 CET

This archive was generated by hypermail 2.3.0 : Sat Feb 07 2015 - 08:36:07 CET