Last active
November 26, 2025 00:03
-
-
Save Xmonpl/3c8585d34c83459ac6a3be1f8cb5d129 to your computer and use it in GitHub Desktop.
Discord notification for OpenMediaVault
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/bash | |
| #CREATED BY XMON FOR OpenMediaVault | |
| DISCORD_WEBHOOK='PUT YOUR WEBHOOK LINK HERE' | |
| generate_post_data() { | |
| cat <<EOF | |
| { | |
| "content": "", | |
| "embeds": [{ | |
| "title": "${OMV_NOTIFICATION_SUBJECT}", | |
| "description": "$(cat ${OMV_NOTIFICATION_MESSAGE_FILE})", | |
| "color": "45973", | |
| "footer": { | |
| "text": "${OMV_NOTIFICATION_DATE}", | |
| "icon_url": "" | |
| } | |
| }] | |
| } | |
| EOF | |
| } | |
| curl -H "Content-Type: application/json" -X POST -d "$(generate_post_data)" $DISCORD_WEBHOOK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to show the output of a file or stdin in bash, and your file includes special characters such as backticks (`) and ", then you can't simply cat filename. You will need to properly escape special characters.
One of the easiest methods to output properly escaped text from a file is to use jq, cut, and rev
Prerequisites
Usage:
Simply pass filename to the following command to escape the file contents to stdout:
jq -Rs . <filename | cut -c 2- | rev | cut -c 2- | revSo, instead of
$(cat ${OMV_NOTIFICATION_MESSAGE_FILE})use this
$(jq -Rs . <${OMV_NOTIFICATION_MESSAGE_FILE} | cut -c 2- | rev | cut -c 2- | rev)So the working bash script to put in /usr/share/openmediavault/notification/sink.d/20discord is here: