Dynamic Title + Body (timestamp + JSON block)

Sends a markdown notification with a rendered JSON code block and current timestamp + hostname baked into the body.

printf '# Alert\n\nTimestamp: %s\n\n```json\n{"status": "critical", "host": "%s"}\n```\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$(hostname)" | curl -sS -H "Authorization: Bearer MYTOKEN" -H "X-Markdown: true" -H "X-Title: Alert from $(hostname)" -d @- https://MYNTFYSITE

Simple Markdown List

Sends a minimal markdown bullet list with hostname and ISO timestamp — good for event logs.

printf '%s\n%s\n%s\n' "## Alert Received" "- Host: $(hostname)" "- Time: $(date --iso-8601=seconds)" | curl -sS -H "Authorization: Bearer MYTOKEN" -H "X-Markdown: true" -H "X-Title: [$(hostname)] Event log" -d @- https://MYNTFYSITE

File Content as Markdown Code Block

Wraps the contents of FILE in a markdown code block and sends it with a timestamped title.

echo "## Log Entry\n\n\`\`\`bash\n$(cat FILE)\n\`\`\`\n\n---\n*Generated at $(date)*" | curl -sS -H "Authorization: Bearer MYTOKEN" -H "X-Markdown: true" -H "X-Title: [$(date '+%H:%M')] File content log" -d @- https://MYNTFYSITE

Send Raw File (URL-encoded)

URL-encodes FILE via jq before sending — safe for arbitrary content that would break raw piping.

cat FILE | jq -Rs @uri | curl -sS -H "Authorization: Bearer MYTOKEN" -H "X-Markdown: true" -H "X-Title: Report $(date '+%Y%m%d')" -d @- https://MYNTFYSITE

Token: Env Var

Reads the token from ~/.ntfy-token into a variable first — avoids the token appearing in the process list.

NTFY_TOKEN="$(cat ~/.ntfy-token)" && cat FILE | jq -Rs @uri | curl -sS -H "Authorization: Bearer $NTFY_TOKEN" -H "X-Markdown: true" -H "X-Title: Report $(date '+%Y%m%d')" -d @- https://MYNTFYSITE

Token: Inline File Read

Reads the token inline at curl execution time — simpler than the env var approach but token briefly visible in args.

cat FILE | jq -Rs @uri | curl -sS -H "Authorization: Bearer $(cat ~/.ntfy-token)" -H "X-Markdown: true" -H "X-Title: Report $(date '+%Y%m%d')" -d @- https://MYNTFYSITE

Notify on Script/Task Completion

Runs your command, captures exit code, then sends pass/fail notification with duration.

START=$(date +%s); bash SCRIPT.sh; CODE=$?; DURATION=$(( $(date +%s) - START )); echo "Exit: $CODE | Duration: ${DURATION}s" | curl -sS -H "Authorization: Bearer MYTOKEN" -H "X-Markdown: true" -H "X-Title: [$(hostname)] SCRIPT.sh $([ $CODE -eq 0 ] && echo '✅ done' || echo '❌ failed')" -d @- https://MYNTFYSITE

Token: Reusable Alias

Defines a shell function so any pipe into ntfy sends a notification — add to .bashrc for persistence.

ntfy() { cat | jq -Rs @uri | curl -sS -H "Authorization: Bearer $NTFY_TOKEN" -H "X-Markdown: true" -H "X-Title: ${2:-Alert}" -d @- https://MYNTFYSITE; }

Use: echo "msg" | ntfy "My Title"