Created
April 28, 2025 14:53
-
-
Save foopis23/ec81ce6c8632ba2c584651652c216869 to your computer and use it in GitHub Desktop.
A script I use on my server to send me discord messages on failed cron jobs
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
## Discord Alert Script | |
# This script sends a message to a Discord channel using a webhook. | |
## Usage | |
# ./discord_alert.sh "<message>" | |
## Example | |
# ./failing_task.sh || ./discord_alert.sh "Example Task failed..." | |
## CONFIG | |
DISCORD_WEBHOOK=<discord_webhook_url> | |
USER_ID=<your_user_id> # USER TO NOTIFY | |
if [ -z "$DISCORD_WEBHOOK" ]; then | |
echo "Please provide a discord webhook url" | |
exit 1 | |
fi | |
if [ -z "$USER_ID" ]; then | |
echo "Please provide a user id to mention" | |
exit 1 | |
fi | |
## CONFIG END | |
MESSAGE=$1 | |
BODY='{"content":"<@'"$USER_ID"'> '$MESSAGE'", "allow_mentions": true}' | |
echo $BODY | |
curl -X POST -H 'Content-type: application/json' --data "$BODY" $DISCORD_WEBHOOK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment