- Jason R. Stevens, CFA
In assuming you run
cron jobs all the time, on all your systems, like I do, you've probably set the crontab options or the
MAILTO variable within
/etc/crontab configuration file or utilized stderr and stdout redirects.
There is a better way!
Cronic, a shell script by Chuck Houpt
to help control the most annoying feature of cron: unwanted emailed output, or 'cram' (cron spam).
Instead of writing:
* * * * * myscript >/dev/null 2>&1
you can now write:
* * * * * cronic myscript
You can avoid sweeping all cron errors under the rug, as we do with stderr and stdout redirection to the
/dev/null black hole while simultaneously cleaning up the readability of your scripts.
Get it on Github
If you need v3 now, fork my copy at thinkjrs/cronic.
If you're a familiar 'nix user just make the script executable and put it somewhere in your path.
'Nix Scripting Step-by-step
For those readers less familiar with 'nix scripting, let's break down step by step how to install Cronic.
Open up your terminal:
- Clone the repo via
git clone email@example.com:thinkjrs/cronic.
- Change directories into the new repo directory
chmod +x cronic.
- Make a
bindirectory in your user
Don't worry, if you have a
bindirectory within your home directory already this will not overwrite it.
- Make sure that
~/binis added to your path via
.bashrc, or whatever shell configuration files you use.
For example, on some systems I have the following in my
... # more stuff added to the PATH
export PATH # now we export it to be used by the shell
- Soft-link your executable cronic script to your
~/bindirectory. Assuming you're still in your cronic directory from Github (if not, navigate your shell there):
CRONIC_LOC=$(pwd)/cronic # set a temporary shell variable
pushd ~/bin # temporarily go into your ~/bin directory
ln -s $CRONIC_LOC cronic # create a soft-link _to_ the CRONIC_LOC named cronic
popd # return to your original cronic directory from Github
You might have noticed the use of
pushd above, in addition to creating some
~/bin directory for your user-space cronic script.
These are intentional as built-in programs and/or conventions commonly used in the GNU/Linux community.
If you're interested in improving overall 'nix skills check out Linux Journey.
I hope you found this useful and thanks for reading!