mycron

Set­ting up cron jobs didn’t change much over time. It works for most users, is very sim­ple to con­fig­ure, and runs very rebust on almost all sys­tems. So why is there another cron service/​daemon? You might ask.

mycron is not a cron service/​daemon. You need an already set up cron ser­vice for using mycron in a rea­son­able way. You need to set up your cronie-​, dcron-​, vixie-​, whatever-​crontab to exe­cute mycron every minute for tak­ing full advan­tage of mycron’s crontabs.

mycron then replaces your reg­u­lar crontab setup. Instead of crontab -e you use mycron -e – It’s not only shorter :) it allows you to set up cron­jobs in a com­pletely new, but very con­ve­nient and stan­dards com­pli­ant way and becomes your com­mand cen­ter for man­ag­ing, cre­at­ing, edit­ing and check­ing (mul­ti­ple) crontabs.

Con­fig­ur­ing your exist­ing cron tab

After you down­loaded and installed mycron, you need to add it to your system’s cron dae­mons crontab (as of now I’ll refer to mycron. Sim­ply replace mycron with your cor­rect call). Usu­ally you start your crontab by enter­ing crontab -e. Check you service’s man­ual for that.

* * * * * mycron

That’s all you need to do in order to enable mycron as your con­ve­nient crontab suite. You can add as many cron tabs as you want. Sim­ply invoke the -u para­me­ter. If your log­ging ser­vice chokes on ANSI color codes, con­sider using mycron -n for sup­press­ing colors.

* * * * * mycron -n
* * * * * mycron -nu foo

The sec­ond line uses crontab foo instead of default crontab. For Every crontab you want to be exe­cuted, you need to place a mycron call in your system’s cron service’s crontab.

How to use mycron

Start­ing mycron with­out any para­me­ters parses and exe­cutes the default crontab. to get a first overview just append -h to your mycron call.

$ mycron -h
Usage: mycron [options] directory

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -u C, --use=C         use crontab C instead of default cron tab
  -e, --edit            edit crontab
  -l, --list            list cronjobs
  -s, --show            show available crontabs
  -c, --check           check crontab for validity
  -n, --no-colors       disable colored output
  -p, --print-examples  show some usage examples
  -x, --x-crontabs      show development crontabs

As you can see, the para­me­ters are very self-​explanatory. When­ever you use one of them, always the default crontab will be used. If you want to use another crontab, pass the para­me­ter -u.

mycron -s

As you can see, mycron uses col­ors a lot. In the above exam­ple it lists all avail­able crontabs. There are three crontabs avail­able. One of them is com­pletely empty, the default crontab con­tains 22 cron­jobs that are all okay. The crontab testinglong con­tains six jobs: five good jobs, and one that is malformed.

mycron -lu testinglong

With mycron -l you can inspect all crontab lines (com­ments and blank lines are ignored). This crontab con­tains only one mal­formed line. Mal­formed lines are dis­played as they are. There could be some­thing com­plete dif­fer­ent. The only prob­lem here is the day-​of-​week set­ting at 8. The week has only seven days …

For edit­ing crontabs there is the para­me­ter -e. When enter­ing mycron -e mycron starts the con­fig­ured edi­tor (see below for extended con­fig­u­ra­tion), for exam­ple vim.

mycron -eu testinglong

As you see: There is a com­ment in the crontab file and a blank line, too. If you want, you can group the con­tents in every line. You can add more spaces or tabs between the date/​time sec­tion, the day(s) of week con­fig­u­ra­tion and the com­mand. to make it look more like a real table.

Note: Please desist from using non-​ASCII char­ac­ters (Ger­man umlauts, other spe­cial sym­bols, etc. It will not break mycron or it’s valid­ity check, but fails on mycron actu­ally exe­cuted by your cron daemon)

But back to our exam­ple. After edit­ing the crontab file, in default con­fig­u­ra­tion mycron checks the valid­ity of the crontab. Because I fixed the 8 and made it a 7, the crontab is now valid.

mycron -eu testinglong

Now there are no more mal­formed cron­jobs in that crontab. This is the same check mycron -c does. If you now list the crontab entries, all entries are okay.

mycron -lu testinglong

Just for com­plete­ness: If you don’t like col­ors, or your ter­mi­nal breaks because of ANSI color codes, you can dis­able them by pass­ing the -n para­me­ter. Exam­ple: check­ing the defauld coro­ntab for validity.

mycron -nc

You should always use mycron -n in your cron service’s cron tab. It will not break some­thing, but if you like log files that are not clut­teered with ANSI color codes, pass­ing -n is always a good idea.

Con­fig­u­ra­tion file and beyond

By default mycron does not need a con­fig­u­ra­tion file (but it will com­plain about miss­ing it so you might want to add one any­ways). With­out con­fig­ured any­thing in file mycron uses $VISUAL for edit­ing files, val­i­dates crontabs after edit­ing crontab files and auto­mat­i­cally cre­ates crontab files if you try to edit a non-​existent crontab.

If you don’t want $VISUAL being invoked when edit­ing files (or you want to get rid of the infor­ma­tion about that), cre­ate a file at ${HOME}/.config/mycron/config.cfg with fol­low­ing content.

[edit]
editor = myeditor

Where myeditor is your favorite text file edit­ing soft­ware. If you still want to use $VISUAL just use it as value for editor. With validate and autocreate you con­trol the other behavior.

[edit]
editor = $VISUAL
validate = True
autocreate = False

validate con­trols the after-​edit-​check. If dis­abled, mycron does not check the crontab for validty after you edited it. This option just exists. You should not dis­able the check. Of course you could just use mycron -c or trust your edit­ing skills, but hey :)

With autocreate = False mycron does not cre­ate the crontab file for you before you edit it. It’ll of course open your edi­tor and lets you edit the file by your­self. It’s more like alit­tle sup­port­ive gad­get: When set to True you start edit­ing with a lit­tle syn­tax reminder – that’s all. If the option is not present, you get a mini tuto­r­ial in every auto­mat­i­cally cre­ated crontab file on how to set up mycron.

Crontabs are stored in crontab files. This files are located at ${HOME}/.config/mycron/crontabs/ and are sim­ple files with CRONTABNAME.crontab file name scheme. Files in this folder with­out the .crontab suf­fix are ignored. You can edit them directly with every pro­gram you want – mycron just helps you with that when you use mycron -eu CRONTABNAME.

As described before mycron uses ISO 8601 date and time noti­fi­ca­tion and a sim­ple place­holder func­tion­al­ity for date and time. mycron profides a handy list of exam­ples when called with para­me­ter -p

mycron -p

As you can see, you can enter pre­pos­ter­ous val­ues (last exam­ple), too. mycrons valid­ity check only checks for seman­tic valid­ity. You need to check for your­self if the entries make sense or not :) But because of the very sim­ple and stan­dard­ized syn­tax it’s quite an easy task …

In addi­tion to mycron -c I cre­ated a vim syn­tax hilight­ing file for valid­ity check­ing. Sim­ply down­load the file, put it into ${HOME}/.vim/syntax/ and edit your ${HOME}/.vim/filetype.vim so that vim auto­mat­i­cally loads the syn­tax hilighting.

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

Maybe you already have a augroup filetypedetect part in that file. Then just add the autocmd into it.

Devel­op­ment crontabs

Lets say you like to test things out a lot and you want to cre­ate a devel­op­ment crontab for try­ing to break mycron and giv­ing me bug reports (g), but you don’t want to see the crontab every­time you type in mycron -l. You can use x- as pre­fix for your crontab file!

mycron -p

Using such crontabs makes no dif­fer­ence from using other crontabs. -x has only an effect in com­bi­na­tion with -l and will be ignored otherwise.

Arch Linux package

Check mycron-​git in AUR, if you’re an Arch Linux user. The pack­age pro­vides mycron, the Vim file, and a two man­pages (sec­tions 1 and 5) for documentation.

Download sources

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