question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

example on how to send notification email if cron fails

See original GitHub issue

as we don’t have notifications based on cronjobs yet (will be implemented in https://github.com/amazeeio/lagoon/issues/618) we could create a simple bash wrapper around commands like drush cron which would check the return code of the command and send an email to the owner of the site. All of this should be built in pure bash and not with any changes in lagoon.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fjgarlincommented, Jun 18, 2021

Could we use the notification system used for the project? If we have Slack or Rocketchat notifications for the project, it’d be great that these notifications would go there by default too, with kind of zero set up or just an env variable to enable these notifications.

1reaction
fagocommented, Mar 24, 2020

thx, this is working great! @shreddedbacon

I’ve slightly improved the script:

#!/bin/bash

TO_ADDR=${CRON_NOTIFY_TO_ADDR:-"your-defaults-there"}
FROM_ADDR=${CRON_NOTIFY_FROM_ADDR:-"NOREPLY <noreply@example.com>"}

ERRFILE=$(mktemp)
SUBJECT="drush cron failure at $LAGOON_SAFE_PROJECT $LAGOON_GIT_BRANCH"
COMMAND="drush cron"

if ($COMMAND 2> >(tee $ERRFILE)) ; then
  echo "Cron exited clean"
else
  echo "Cron failed, sending email"
  ERROR=$(<$ERRFILE)
  sendmail $TO_ADDR <<EOF
To: $TO_ADDR
Subject: $SUBJECT
From: $FROM_ADDR

Command $COMMAND failed at $LAGOON_SAFE_PROJECT $LAGOON_GIT_BRANCH.
The error was:
$ERROR
EOF
rm $ERRFILE
fi

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get email when a cron job fails (Example)
Get email when a cron job fails · Redirect all of your standard output to /dev/null or to some file. · Use the...
Read more >
example on how to send notification email if cron fails #1653
Send email for failing cron · TO_ADDR to change the recipients · FROM_ADDR to change the sender · SUBJECT to change the subject...
Read more >
How to get e-mail from (failed) cron-jobs in Ubuntu?
By default, cron will email the owner of the account under which the crontab is running. The system-wide crontab is in /etc/crontab runs ......
Read more >
How to Send Email From Cron Jobs
You put a MAILTO=you@example.org line in your crontab, and, when a job fails, cron will send a notification to the specified address using ......
Read more >
Alerting on a failed cron job
Can you post your crontab entry? By default an email would be generated if cronjob returns a non-zero result. And what do you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found