3 ms·
If you want super minimal, something like this might work? #!/bin/bash # Add this script to cron to run at whatever duration you desire. # URL to be ch
by runjake 2y ago
If you want super minimal, something like this might work?
#!/bin/bash
# Add this script to cron to run at whatever duration you desire.
# URL to be checked
URL="https://example.com/test.php"
# Email for alerts
EMAIL="root@example.com"
# Perform the HTTP request and extract the status code with 10 second timeout.
STATUS=$(curl -o /dev/null -s -w "%{http_code}\n" --max-time 10 $URL)
# Check if the status code is not 200
if [ "$STATUS" -ne 200 ]; then
# Send email alert
echo "The URL $URL did not return a 200 status code. Status was $STATUS." | mail -s "URL Check Alert" $EMAIL
# Instead of email, you could send a Slack/Teams/PagerDuty/Pushover/etc, etc alert, with something like:
curl -X POST https://events.pagerduty.com/...
fi
Edit: updated with suggested changes.
- divbzero 2y agoAs a slight variation, you could send an alert to the PagerDuty API by replacing “Send email alert” with something like: # Send PagerDuty alert curl -X POST https://events.pagerduty.com/...
- runjake 2y agoAdded. In fact, this is what I'd recommend (though I use Pushover), because then you don't have to be concerned with email setup, not getting caught in spam filters, firewalls, etc. You could also send a Slack/Teams alert with a similar POST. For some reason, I thought I had read that OP wanted to send an email.
- zikduruqe 2y agoOr apprise for a whole bunch of notifications. https://github.com/caronc/apprise https://github.com/caronc/apprise
- drivers99 2y agoYou should include a timeout in the curl to detect if it hangs, or if it gets slower than it should be.
- runjake 2y agoAdded!