YuanL
YuanL

Reputation: 67

How to get notified when crontab fails

Trying to detect if my crontab job fails and if so I would want it to notify me but I could not find any information on that but the following from the old crontab.guru. What does the following mean?

&& curl -sm 30 k.wdt.io/<email-address>/<cronjob-name>?c=

Is there a good way to create a script in case crontab fails?

Using Mac OS

Upvotes: 2

Views: 1122

Answers (2)

Pēteris Caune
Pēteris Caune

Reputation: 45112

wdt.io was a cron job monitoring service. It was discontinued a while back.

The idea with the && curl syntax is to run a HTTP request every time after your cron job completes successfully (with an exit status 0).

  • If the cron job does not run at all (e.g. because the server is powered off) then obviously the curl call will not run
  • If the cron job finished with a non-zero exit status, the part after && will not be executed
  • If server's network connection is down, then curl may attempt a HTTP request, but it will not reach the monitoring service

Either way, the idea with wdt.io was to check if it is receiving HTTP requests on a defined schedule. As soon as a request does not arrive on time, wdt.io would detect that and notify you.

This is a form of Dead Man's Switch and there is a number of SaaS offering this service. You can search the web for "cron job monitoring" and you will find them no problem :-)

Upvotes: 0

user1986815
user1986815

Reputation:

crontab -e

[email protected]
* * * * * echo 'hi' >> hi.txt

please check if you have a MTA like this :

netstat -tlnp |grep :25

or using sudo

sudo netstat -tlnp |grep :25

and you should get a row like

root@linux:~# netstat -tlnp |grep :25
tcp    0    0    192.168.1.100:25    0.0.0.0:*    LISTEN    1322/master

if you do not get that then you install ssmtp

sudo apt install ssmtp
sudo dpkg-reconfigure ssmtp

Upvotes: 1

Related Questions