Skip to content

Instantly share code, notes, and snippets.

@jmrushing
Created August 20, 2026 04:34
Show Gist options
  • Select an option

  • Save jmrushing/090da0979b69606038193cb3c534306d to your computer and use it in GitHub Desktop.

Select an option

Save jmrushing/090da0979b69606038193cb3c534306d to your computer and use it in GitHub Desktop.
Wrapper script for discord.sh to report Docker container states to my Discord server
#!/bin/bash
######################################################################
# Custom script for discord.sh (github.com/fieu/discord.sh)
# to query my Docker containers' statuses
# depending on if the container is running or not.
# A tmpfile is used to generate the full discord.sh command on-the-fly
# That command is then executed and the tmpfile removed
######################################################################
SCRIPT_NAME=$(basename "$0")
FOOT_ICON="https://raw.githubusercontent.com/odb/official-bash-logo/master/assets/Logos/Icons/PNG/24x24.png" # Bash logo FTW
COLOR="0x2073f7" # Blue
WEBHOOK="https://discord.com/api/webhooks/YOURPRIVATEWEBHOOK/GOESHERE"
DS2D_CMD=$(mktemp /tmp/"${SCRIPT_NAME}".XXXXXX)
trap 'rm "$DS2D_CMD"' EXIT
cat << EOF > "$DS2D_CMD"
discord.sh \\
--webhook-url="$WEBHOOK" \\
--color "$COLOR" \\
--description "Status Report" \\
--footer-icon "$FOOT_ICON" \\
--footer "$SCRIPT_NAME" \\
--timestamp \\
EOF
for c in $(docker ps -a --format '{{.Names}}'); do # Loop over all containers and assign checkmark or red X icon based on status
[[ "$(docker ps -a -f name="^${c}$" --format '{{.State}}')" == "running" ]] && icon=':white_check_mark:' || icon=':x:'
printf '\t%s\n' "--field \"$icon $c;;false\" \\" >> "$DS2D_CMD"
done
sed -i '$ s/.$//' "$DS2D_CMD" # chop off the last trailing backslash
bash "$DS2D_CMD" # run it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment