Created
December 7, 2025 22:43
-
-
Save Jocadbz/8ad7de68cb41f9f0d7c9358ebe7424e4 to your computer and use it in GitHub Desktop.
Little bash function to start a command and notify you on discord when it is finished through a webhook.
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_notify() { | |
| local WEBHOOK="YOUR_WEBHOOK_API" | |
| local USER_ID="YOUR_USER_ID" | |
| curl -s -H "Content-Type: application/json" \ | |
| -d "{\"content\": \"<@$USER_ID> Started\`\`\`bash\n$*\n\`\`\`\"}" \ | |
| "$WEBHOOK" > /dev/null | |
| local START=$(date +%s) | |
| eval "$@" | |
| local EXIT_CODE=$? | |
| local END=$(date +%s) | |
| local DURATION=$((END - START)) | |
| if [ $EXIT_CODE -eq 0 ]; then | |
| local EMOJI="Success" | |
| local STATUS="SUCCESS" | |
| else | |
| local EMOJI="Failed" | |
| local STATUS="FAILED (code $EXIT_CODE)" | |
| fi | |
| curl -s -H "Content-Type: application/json" \ | |
| -d "{\"content\": \"<@$USER_ID> $EMOJI **$STATUS** after ${DURATION}s\n\`\`\`bash\n$*\n\`\`\`\"}" \ | |
| "$WEBHOOK" > /dev/null | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment