Send a Slack Message from Cron
To send a Slack notification on a schedule, curl your Slack incoming-webhook URL from cron with a JSON payload. This is ideal for daily summaries or alerting when a job finishes.
The crontab line
Create an incoming webhook in Slack, then crontab -e and add (9 AM on weekdays):
0 9 * * 1-5 /usr/bin/curl -fsS -X POST -H 'Content-type: application/json' --data '{"text":"Daily standup reminder"}' https://hooks.slack.com/services/XXX/YYY/ZZZ >/dev/null 2>&1
Include command output
Capture output into the payload from a small wrapper script:
MSG=$(df -h / | tail -1); curl -fsS -X POST -H 'Content-type: application/json' --data "{\"text\":\"$MSG\"}" $WEBHOOK
Put multi-step logic in a .sh file and call that from cron — escaping JSON inline in a crontab is error-prone.
Keep the webhook secret
Store the URL in the script or an env file with chmod 600, not in a public repo — anyone with the URL can post to your channel.
FAQ
How do I send a Slack message from cron?
curl -X POST -H 'Content-type: application/json' --data '{"text":"..."}' your-webhook-url from a cron line. Create an incoming webhook in Slack first.
How do I put command output in the Slack message?
Use a wrapper .sh script: capture output into a variable and build the JSON payload from it, then curl the webhook. Inline JSON in crontab is hard to escape.
Is it safe to keep the Slack webhook URL in cron?
Keep it in a chmod 600 script or env file and out of public repos. Anyone with the webhook URL can post to your channel.