mycron

mycron is an ISO 8601 com­pli­ant cron ser­vice that allows you to replace any exist­ing cron daemon/​service when already using sys­temd timers for sys­tem related cronjobs.

Fea­tures

It’s pos­si­ble to set up timed oper­a­tions exact up to a minute. “Soft“ val­ues (i.e. “once within an hour/​day but I don’t care when exactly”) are not pos­si­ble. mycron only exe­cutes com­mands that are exactly timed for a spe­cific date.

mycron runs in mul­ti­ple instances each for one user with user priv­i­leges (see below for set­ting it up via sys­temd). Users are able to sim­ply start mycron in the back­ground in a screen/​tmux ses­sion or via disown.

How to use

mycron has a very lim­ited set of com­mand line options because it usu­ally runs as a ser­vice in background.

$ mycron -h
Usage: mycron [options]

Options:
  --version        show program's version number and exit
  -h, --help       show this help message and exit
  -e, --edit       edit crontab
  -l, --list       list cronjobs
  -c, --check      check crontab for validity
  -o, --once       only run once instead of daemon-like

The most used com­mand will be mycron -e for edit­ing the crontab. If the users sets It up for the first time it’ll be cre­ated in ${HOME}/.config/mycron/mycron.crontab with a lit­tle note on how to prop­erly set up cron­jobs for mycron.

If start­ing there may be a delay to being minute-​exact. There is an infor­ma­tion about the delay in sec­onds. After the delay mycron starts exe­cut­ing the crontab peri­od­i­cally begin­ning with the given time.

Crontab syn­tax

Cron­job def­i­n­i­tions in mycron’s crontab file con­sists of three parts. The first part is the date/​time infor­ma­tion fol­lowed by the day-​of-​week value on sec­ond and the third part is the com­mand that will be exe­cuted on the spec­i­fied date. A sin­gle colon (.) is used as wild­card char­ac­ter in the date/​time def­i­n­i­tion or for the day-​of-​week value.

All parts are sep­a­rated by one or more spaces or tabs and sin­gle lines are sep­a­rated by one or more line breaks. Com­ments are ini­ti­ated by a num­ber sign (#). Please note that non-​ASCII (for exam­ple Ger­man umlauts) char­ac­ters could break exe­cut­ing the cron­jobs prop­erly. Desist from using them.

....-..-..T..:.. .    command   # Example 1
....-..-..T18:57    7 command   # Example 2
....-..-..T07:38 126  command   # Example 3
2014-10-..T..:00  4   command   # Example 4
....-12-..T14:.. .    command   # Example 5
2018-01-14T10:45  2   command   # Example 6

The com­mand command in the exam­ple will be exe­cuted on dif­fer­ent times. The first exam­ple will be exe­cuted on every run. By default the crontab will be checked once a minute.

The sec­ond exam­ple gets exe­cuted at 6:57pm on every Sun­day (7 refers to Sun­day in ISO 8601). The third exam­ple gets exe­cuted at 7:38am on every Mon­day, Tues­day and Saturday.

The third exam­ple will only be exe­cuted on every Thurs­day in Octo­ber 2014 at every full hour. The fifth exam­ple runs every­day in every Decem­ber on every minute at 2pm.

The last exam­ple will never be exe­cuted because 2018-​01-​14 is a Sun­day (7) and not a Tues­day 2

Con­fig­u­ra­tion

A con­fig­u­ra­tion file can be cre­ated at ${HOME}/.config/mycron/mycron.conf. As of now it only uses one sec­tion with one sin­gle option.

[default]
editor = foo

This sets the edi­tor pro­gram for edit­ing crontabs via mycron -e to foo. By default the envi­ron­ment vari­able $VISUAL will be used. You can edit the crontab man­u­ally with any pro­gram you want by directly open­ing ${HOME}/.config/mycron/mycron.crontab in an edi­tor of your choice.

After man­u­ally edit­ing a crontab you should check it for tech­ni­cal valid­ity via mycron -c. Seman­tic valid­ity (see exam­ple 7 in pre­vi­ous sec­tion) will not be checked.

Vim syn­tax file

For bet­ter vis­i­bil­ity I cre­ated a Vim syn­tax high­light­ing file that assists the user by high­light­ing a valid crontab line in a defined way.

Sim­ply down­load the file, put it into ${HOME}/.vim/syntax andedit your ${HOME}/.vim/filetype.vim so that Vim auto­mat­i­cally loads the syn­tax high­light­ing file when edit­ing a crontab.

augroup filetypedetect
autocmd BufNewFile,BufRead \*.crontab setf crontab
augroup END

If your file already con­tains an autogroup filetypedetect part, sim­ply add the autocmd line to it.

Arch Linux package

Check mycron-​git in AUR for an ARch Linux pack­age con­tain­ing mycron, a sys­temd ser­vice unit and var­i­ous man­pages for documentation.

Download sources

See GitHub for details. All my code is available under GPLv3 or later.