Skip to content

Commit

Permalink
docs: update README with notice of why this fork exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed May 16, 2022
1 parent e0f4bc7 commit a6c5b34
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
See http://habilis.net/cronic/. Keeping a copy safe for personal use.

# Cronic

## A cure for Cron's chronic email problem
> A cure for Cron's chronic email problem
**NOTE:** This [fork](https://github.com/justincase/cronic) exists for the sole purpose of packaging a tagged version of cronic to use in my personal [Homebrew tap](https://github.com/justintime50/homebrew-formulas) and does not differ from the original.

The Disease:

0 1 * * * backup >/dev/null 2>&1
```bash
0 1 * * * backup >/dev/null 2>&1

The Cure:

0 1 * * * cronic backup
0 1 * * * cronic backup
```

Cronic is a shell script to help control the most annoying feature of
cron: unwanted emailed output, or "cram" (cron spam). If the Unix Haters
list was still active, I would submit the rant below to gain membership.

- [Chuck Houpt](http://habilis.net/chuck/)

## The Disease

One of the best features of cron is its automatic email - it is also its
One of the best features of cron is its automatic email - it is also its
worst feature. Cron automatically emails the output of a cron job to the
user. On the face of it, this sounds like a great idea. Cron jobs can run
automatically in the background for months at a time - so getting an email
when a problem occurs sounds useful.

Unfortunately, cron's idea of "output" is simultaneously too broad and too
narrow to actually be useful. Cron considers any output to be significant

- including standard output. This interacts badly with many unix commands,
which often send status info to standard out. Some commands have a quiet
options, but that can turn off all error output too. To make matters worse,
Expand All @@ -38,10 +42,13 @@ to run without output, but still reports all errors. Following the principle
of "Worse is Better", the typical solution is to sweep it all under the carpet
by redirecting all output to /dev/null, and hoping for the best:

0 1 * * * backup >/dev/null 2>&1
```bash
0 1 * * * backup >/dev/null 2>&1
```

Now when your cron job fails, you will never know about it. Using cron to backup
your files? Sorry, the cron job has been failing due to permission errors for months

- all your files are gone.

Could cron be fixed? Although almost all current implementation of cron are open source,
Expand All @@ -58,47 +65,53 @@ non-zero result code. Cronic filters Bash execution traces (or anything matching
the error output, so jobs can be run with execution tracing to aid forensic debugging.
Cronic has no options, it simply executes its arguments.

0 1 * * * cronic backup
```bash
0 1 * * * cronic backup
```

With cronic, you can turn on Bash's strict error handling and debug options (exit on error,
unset variable detection and execution tracing) to make sure problems are caught early.
For example:

#!/bin/bash
```bash
#!/bin/bash

set -o errexit -o nounset -o xtrace
set -o errexit -o nounset -o xtrace

cp -rp data1 /backup
cp -rp data2 /backup
cp -rp data3 /backup
cp -rp data1 /backup
cp -rp data2 /backup
cp -rp data3 /backup
```

When an error is detected, Cronic outputs a report listing the result code, error output, and
combined trace and error output. The combined output can help put error messages in context.
An example:

From: user@example.net (Cron Daemon)
To: user@example.net
Subject: Cron <user@server> cronic backup
```bash
From: user@example.net (Cron Daemon)
To: user@example.net
Subject: Cron <user@server> cronic backup

Cronic detected failure or error output for the command:
backup
Cronic detected failure or error output for the command:
backup

RESULT CODE: 1
RESULT CODE: 1

ERROR OUTPUT:
cp: data2: Permission denied
ERROR OUTPUT:
cp: data2: Permission denied

STANDARD OUTPUT:
STANDARD OUTPUT:

TRACE-ERROR OUTPUT:
+ cp -rp data1 /backup
+ cp -rp data2 /backup
cp: data2: Permission denied
TRACE-ERROR OUTPUT:
+ cp -rp data1 /backup
+ cp -rp data2 /backup
cp: data2: Permission denied
```

### Version History

* v2 - Corrected command evaluation, so shell meta-chars are preserved correctly (Thanks to Frank Wallingford for the fix).
* v1 - Initial release.
- v2 - Corrected command evaluation, so shell meta-chars are preserved correctly (Thanks to Frank Wallingford for the fix).
- v1 - Initial release.

### Releated Projects

Expand Down

0 comments on commit a6c5b34

Please sign in to comment.