Coder Social home page Coder Social logo

croncape's Introduction

Croncape

Croncape wraps commands run as cron jobs to send emails only when an error or a timeout has occurred.

Out of the box, crontab can send an email when a job generates output. But a command is not necessarily unsuccessful "just" because it used the standard or error output. Checking the exit code would be better, but that's not how crontab was standardized.

Croncape takes a different approach by wrapping your commands to only send an email when the command returns a non-zero exit code.

Croncape plays well with crontab as it never outputs anything except when an issue occurs in Croncape itself (like a misconfiguration for instance), in which case crontab would send you an email.

Installation

Download the binaries or go install github.com/symfonycorp/croncape@latest.

Usage

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

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

That's it!

Note that the MAILTO environment variable can also be defined globally in /etc/crontab; it supports multiple recipients by separating them with a comma.

You can also customize the email sender by setting the MAILFROM environment variable.

If you need to use "special" shell characters in your command (like ; or |), don't forget to quote it and wrap the command in a shell:

0 6 * * * croncape bash -c "ls -lsa | true"

Besides sending emails, croncape can also kill the run command after a given timeout, via the -t flag (disabled by default):

0 6 * * * croncape -t 2h ls -lsa

If you want to send emails even when commands are successful, use the -v flag (useful for testing).

Use the -h flag to display the full help message.

Croncape is very similar to cronwrap, with some differences:

  • No dependencies (cronwrap is written in Python);

  • Kills a command on a timeout (cronwrap just reports that the command took more time to execute);

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

  • Reads the email from the standard crontab MAILTO environment variable instead of a -e flag.

For a simpler alternative, have a look at cronic.

croncape's People

Contributors

fabpot avatar tucksaun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

croncape's Issues

Write stdout to a log file

Hi,

It's not an issue, but I'm wondering if it's possible to write the standard output to a file without the -v parameter. I'd like to keep the email sent only when there is an error and log stdout to a file on each cron execution.

Really nice job by the way. 👍

Installation is not working

Hello @fabpot,

When i'm trying to install Croncape following your documentation (https://github.com/symfonycorp/croncape#installation), like this :

go get github.com/symfonycorp/croncape

I got this error :

go: go.mod file not found in current directory or any parent directory.
	'go get' is no longer supported outside a module.
	To build and install a command, use 'go install' with a version,
	like 'go install example.com/cmd@latest'
	For more information, see https://golang.org/doc/go-get-install-deprecation
	or run 'go help get' or 'go help install'.

When i follow recommendations found here https://go.dev/doc/go-get-install-deprecation, like this :

go install github.com/symfonycorp/[email protected]

Everything works as expected,

I guess the command is not the same, depending on the version of Go used localy. I'm using go version go1.18.1 linux/amd64

Thank you,

Jérôme

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.