How to Create a Simple Website Uptime Monitor Using SSH and Cron

On this page
  1. Before You Begin
  2. Step 1: Create a Webhook
  3. Discord
  4. Slack
  5. Step 2: Connect via SSH
  6. Step 3: Create the Monitoring Script
  7. Step 4: Make the Script Executable
  8. Step 5: Schedule Automatic Checks
  9. Understanding the Script
  10. Possible Improvements
  11. Summary

Monitoring your website’s availability helps you identify outages and service issues before your visitors report them. While many third-party monitoring services are available, you can also create a simple uptime monitoring solution using SSH access, a shell script, and a scheduled cron job.

This approach allows you to periodically check your website and send notifications to services such as Discord or Slack when a problem is detected.

Before You Begin

You will need:

  • SSH access to your hosting account
  • Cron job support
  • A Discord or Slack webhook URL
  • Basic familiarity with the Linux command line

Step 1: Create a Webhook

Discord

To create a Discord webhook:

  1. Open your Discord server settings.
  2. Navigate to Integrations → Webhooks.
  3. Create a new webhook.
  4. Select the target channel.
  5. Copy the generated webhook URL.

Slack

To create a Slack webhook:

  1. Open your Slack workspace settings.
  2. Enable Incoming Webhooks.
  3. Create a new webhook.
  4. Select the destination channel.
  5. Copy the webhook URL.

Keep this URL secure, as anyone with access to it can send messages to the configured channel.

Step 2: Connect via SSH

Connect to your hosting account:

ssh username@yourdomain.com

Navigate to your home directory:

cd ~

Create a new script:

nano uptime_monitor.sh

Step 3: Create the Monitoring Script

Paste the following script into the file and adjust the configuration values:

#!/bin/bash

URL="https://yourdomain.com"
WEBHOOK_URL="https://your-webhook-url"
PLATFORM="discord"

STATUS=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 10 "$URL")

if [ "$STATUS" -ne 200 ]; then
    MESSAGE="Website check failed for $URL. HTTP status: $STATUS"

    if [ "$PLATFORM" = "discord" ]; then
        PAYLOAD="{\"content\": \"$MESSAGE\"}"
    else
        PAYLOAD="{\"text\": \"$MESSAGE\"}"
    fi

    curl -H "Content-Type: application/json" \
         -X POST \
         -d "$PAYLOAD" \
         "$WEBHOOK_URL" >/dev/null 2>&1
fi

Save the file and exit the editor.

Step 4: Make the Script Executable

Grant execution permissions:

chmod +x uptime_monitor.sh

You can run the script manually to verify it executes successfully:

./uptime_monitor.sh

If the website returns HTTP status code 200, no notification will be sent.

Step 5: Schedule Automatic Checks

Open your user crontab:

crontab -e

Add the following line to execute the script every five minutes:

*/5 * * * * /home/username/uptime_monitor.sh

Replace the path with the actual location of your script.

Save and exit the editor.

The monitoring process will now run automatically at five-minute intervals.

Understanding the Script

The script relies on several useful curl options:

Option Purpose
-s Runs curl in silent mode
-o /dev/null Discards the page content
-w "%{http_code}" Outputs only the HTTP response code
--connect-timeout 10 Stops waiting after 10 seconds

This allows the script to quickly determine whether the website is responding normally without downloading the entire page.

Possible Improvements

Once the basic monitoring is working, you can expand it further:

  • Monitor multiple websites from a single script
  • Alert only after multiple consecutive failures
  • Check for specific page content instead of only HTTP status codes
  • Log outages to a file for reporting purposes
  • Monitor additional services such as APIs, databases, or application endpoints

Summary

Using SSH, cron jobs, and webhooks, you can create a lightweight uptime monitoring system that automatically checks your website and sends notifications when problems occur.

While this approach is not a replacement for enterprise monitoring platforms, it can provide a simple and effective way to keep track of website availability using tools already available on most hosting accounts.

Didn't find an answer?

Our support team is here for you 24/7 – write to us and we will help you sort it out.