Skip to content

Instantly share code, notes, and snippets.

@supersonictw
Last active December 15, 2024 08:18
Show Gist options
  • Save supersonictw/ef01b51032cff6299246abe02de04099 to your computer and use it in GitHub Desktop.
Save supersonictw/ef01b51032cff6299246abe02de04099 to your computer and use it in GitHub Desktop.
Execute daily tasks and sends a notification upon successful completion.
#!/bin/sh
# daily_tasks.sh - Execute daily tasks and sends a notification upon successful completion.
# SPDX-License-Identifier: MIT (https://ncurl.xyz/s/o_o6DVqIR)
# https://gist.github.com/supersonictw/ef01b51032cff6299246abe02de04099
# crontab -e
# 0 3 * * * sh /somewhere/daily_tasks.sh >/dev/null 2>&1 # execute silently at 3 a.m every day
NOTIFY() {
DATE_NOW="$(date)"
curl \
-X POST \
-H "Content-Type: application/json" \
-d "{\"content\":\"Task has been executed at \`$DATE_NOW\`.\"}" \
"$1"
}
sh "your_task_here.sh" &&
NOTIFY "https://your_webhook.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment