Skip to content

Instantly share code, notes, and snippets.

@ferbass
Created August 14, 2023 01:49
Show Gist options
  • Save ferbass/2b53ce08a9fec2eb98fb499dc5fda27a to your computer and use it in GitHub Desktop.
Save ferbass/2b53ce08a9fec2eb98fb499dc5fda27a to your computer and use it in GitHub Desktop.
Post to slack if your host requires reboot
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
# Function to send a message to Slack
send_slack_notification() {
message="Reboot is required on $(hostname)"
slack_webhook_url="YOUR_SLACK_WEBHOOK"
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"$message\"}" "$slack_webhook_url"
}
# Check if a reboot is required
if [ -e /var/run/reboot-required ]; then
send_slack_notification
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment