Created
February 18, 2022 01:05
-
-
Save ankitdbst/7523e77e0f08842186ede8116478cabb to your computer and use it in GitHub Desktop.
Run cron with SNS notification on failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Usage: Add below to crontab -e | |
# * * * * run.sh script | |
# | |
# This would run npm --prefix /path/to/app run script | |
if [ -z "$1" ] | |
then | |
echo "No script specified" | |
exit; | |
fi | |
cmdoutput=$(/usr/bin/npm --prefix /path/to/app run $1 2>&1) | |
exitcode=$? | |
echo "$cmdoutput" | |
if [ $exitcode -ne 0 ]; then | |
aws sns publish \ | |
--topic-arn "${AWS_NOTIFY_TOPIC}" \ | |
--message "cron $1 failed with error: ${exitcode}\n\n${cmdoutput}" | |
exit $exitcode | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment