Scron

Scheduler for Laptops

Scron schedules commands to run daily, weekly, monthly, or annually. If your machine is
off, scron will attempt to run a scheduled command as soon as possible. See Scron on GitHub.

Install

# Mac
$ brew install hughbien/tap/scron

# Linux
$ wget -O /usr/local/bin/scron https://github.com/hughbien/scron/releases/download/v0.1.2/scron-linux-amd64
$ chmod +x /usr/local/bin/scron

# Source (requires Crystal)
$ git clone https://github.com/hughbien/scron.git
$ cd scron
$ make
$ make install

For Mac, use Homebrew: brew install hughbien/tap/scron

For Linux, download the latest binary: scron-linux-amd64. MD5 checksum is 68f821fb86132ad02fc5ba116af696eb

To compile from source, you'll need Crystal installed first. Then checkout the repository and run make && make install

Configuration

$ crontab -e
0 */2 * * * scron -r
# in ~/.scron file
1d         daily-cmd
7d         7-days-cmd
Mo,Fr      mondays-and-fridays-cmd
1st,23rd   twice-a-month-cmd
4/15       once-a-year-cmd
# example: run backup script every two days
2d /path/to/backup.sh arg1 arg2

# example: tell yourself Happy Birthday every year
3/14 say "Happy Birthday!"

First, setup cron to run it every two hours.

Scron can be configured via the ~/.scron file. It uses a simple format: left column for schedule and right column for unix command. Comment lines start with #. Blank lines are ignored.

Scron will attempt to run whenever a schedule goes stale. For example, if its been 25 hours since the last run and the command is scheduled for 1d. Or if your laptop was off on Friday but on Saturday, and the command was scheduled for Fridays.

Debugging

# in ~/.scrondb
2020-03-14.02:00 say "Happy Birthday!" 
2020-05-20.04:00 /path/to/backup.sh arg1 arg2
# in ~/.scronlog
=> 2020-05-20.04:00 running
=> 2020-05-20.04:00 /path/to/backup.sh arg1 arg2 (start)
Running backup...
Backup was successful!
=> 2020-05-20.04:00 /path/to/backup.sh arg1 arg2 (exit=0)
=> 2020-05-20.04:00 finished

Last run timestamps are stored in ~/.scrondb. STDOUT of commands with timestamps are logged in ~/.scronlog. Commands returning non-zero status are considered a failure. Scron will try to re-run them after two hours.