Skip to content

Commit

Permalink
added support for the MAILTO env var
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 30, 2017
1 parent 81faaf9 commit 66934bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ Usage

When adding a command in crontab, prefix it with `croncape`:

0 6 * * * croncape -e "[email protected]" ls -lsa
[email protected]
0 6 * * * croncape ls -lsa

That's it!

You can also send emails to more than one user by separating emails with a comma:
Note that the `MAILTO` environment variable can also be defined globally in
`/etc/crontab`; it supports multiple recipients by separating them with a comma.

Alternatively, you can also the `-e` flag to define emails:

0 6 * * * croncape -e "[email protected]" ls -lsa
0 6 * * * croncape -e "[email protected],[email protected]" ls -lsa

Besides sending emails, croncape can also kill the run command after a given
Expand All @@ -52,7 +57,9 @@ Croncape is very similar to [cronwrap][2], with some differences:
more time to execute);

* Tries to use `sendmail` or `mail` depending on availability (cronwrap only
works with `sendmail`).
works with `sendmail`);

* Reads the email from the standard crontab `MAILTO` environment variable.

For a simpler alternative, have a look at [cronic][3].

Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func main() {

req.command = flag.Args()

if req.emails == "" && os.Getenv("MAILTO") != "" {
req.emails = os.Getenv("MAILTO")
}

r := execCmd(wd, req)

if r.killed || r.code != 0 || r.request.verbose {
Expand Down

0 comments on commit 66934bf

Please sign in to comment.