Cronguard was developed to evaluate cronjobs, you could say: "cron can do this alone" - yes and no. Yes cron can do that but it is prone to errors, at least for piped commands, imagine you execute the following: true | false | true && echo "success" || else echo "fail"
Guess what is the output here - success and with that the logic of the results for cronjobs is wrong. The reason is that every command of a piped command chain has its own return value which is stored in a shell array variable - ${PIPESTATUS[*]} - and the bash(and thus cron) uses always the last one as the "result".
The second purpose of Cronguard is to get rid of these annoying mails you have to check as an admin every day: 'Yes the cronjob XY on Server Z was successful...'
Instead of disabling the mailing functionality from cron let Cronguard do the (dirty and lazy) work. Cronguard will only send mails in case of failed cronjobs and cronjobs that run longer than one day. About successfully executed ones Cronguard does not care.
How it works
You let the cron_wrapper.sh script execute your cronjobs, just put the script in front of your cronjob the following way:
It will send the following data(token, ident, host, start time, command and action) via curl to the cronguard server which writes them to a database, executes the cronjob and checks if the command(s)/script were executed successfully and makes then a second curl to the server with the result(fail or success). On the server runs a daemon which checks once per minute if there are new database entries, entries with a 'success' as a result are just deleted, entries with a 'fail' as a result are sent by mail - and then deleted, if there is no result(NULL) and the cronjob runs longer than one day(86400 seconds) a mail is also sent and the entry is deleted. In order to get it to work generate a token, store the token in /opt/cronguard/token.inc.sh (this is the location where the wrapper expects it), download the wrapper script cron_wrapper.sh and you can start. Besides the generating of token you can - if you are not sure if your token is valid - validate your token and of course delete your token(and your email address). If you have forgotten or lost your token you can have your token sent to you on the corresponding page. This application also has a simple api, you can check if there are entries(for your token), you can call this api as follows:
https://cronguard.ddns.net/cronguard_api.php?method=api&token=`your_token`
Some further and additional information can be found here: Cronguard on GitHub
If you want to host cronguard yourself you can download everything you need from the GitHub link (including .deb packages). Even a minimal invasive testing is possible as there is a docker image on DockerHub: Cronguard on Docker Hub
What do i need
Only 2 things, the script cron_wrapper.sh which executes your cronjobs and a valid token. You can get both here, the cron_wrapper.sh script from the download page Download Section, and the token you can generate at the generate token page Generate Token (all you need for that is a valid email address)
What does it cost
NOTHING, using this service is absolutely and 100% for free! If you have a bad conscience about not paying for it - please support your local animal shelter.
About the author
My name is andreas, i'm a linux administrator/system engineer and open source enthusiast. I live in berlin and worked here for various companies.
Startups as well as public service and established companies. More about me and what i do on the following social media buttons and about cronguard on github and dockerhub.
In case of any questions, critics, praise or suggestions don't hesitate to contact me.