📑 Table des matières

Cron + IA : automatiser des tâches intelligentes 24/7

Automatisation 🟡 Intermédiaire ⏱️ 14 min de lecture 📅 2026-02-24

You already use cron on your Linux server to run scripts at fixed times? Now imagine a system that doesn’t just blindly execute a command, but thinks, analyzes context, and intelligently decides the best action to take. That’s exactly what combining cron with autonomous AI enables.

In this guide, we’ll dive deep into how to transition from classic cron to smart cron powered by AI, using OpenClaw as the orchestration platform. You’ll learn the fundamental differences between the two approaches, concrete automation examples, and a step-by-step guide to setting up your own intelligent tasks running 24/7.


🔄 Classic Cron vs. AI Cron: Two Philosophies

Traditional Cron: Reliable but Blind

Unix cron has existed since the 1970s. Its principle is simple: execute a command at a precise time, based on a time expression (the famous * * * * * syntax).

# Classic example: daily backup at 3 AM
0 3 * * * /usr/local/bin/backup.sh

# Disk space check every hour
0 * * * * /usr/local/bin/check_disk.sh

The problem? This script runs no matter what. Even if the backup is unnecessary (no changes), even if disk space is fine. It can’t adapt its behavior to context.

AI Cron: Contextual and Intelligent

With an AI agent, the paradigm shifts entirely. The agent receives an instruction but reasons before acting:

  • Checks if the action is necessary
  • Adapts its response to context
  • Can escalate (alert) or ignore based on severity
  • Produces human-readable summaries
Criteria Classic Cron AI Cron (OpenClaw)
Execution Blind, always Contextual, intelligent
Response Exit code (0/1) Natural language analysis
Adaptation None Adjusts based on context
Escalation Manual if/else scripts Autonomous decision
Cost Near-zero LLM tokens (optimizable)
Maintenance Scripts to maintain Natural language prompts
Monitoring Raw logs Intelligent summaries
Multi-tasking 1 cron = 1 script 1 heartbeat = N checks

🧠 OpenClaw’s Two Mechanisms: Heartbeat and Cron

OpenClaw offers two complementary mechanisms for temporal automation. Understanding their differences is key to architecting your automations effectively.

Heartbeat: Your Agent’s Pulse

The heartbeat is a periodic agent cycle in the main session. By default, it triggers every 30 minutes. The agent "wakes up," checks its checklist (HEARTBEAT.md), and decides what to do.

// Configuration in openclaw config
{
  agents: {
    defaults: {
      heartbeat: {
        every: "30m",
        target: "last",
        activeHours: { start: "08:00", end: "22:00" },
      }
    }
  }
}

Heartbeat strengths:

  • Batch multiple checks: A single agent cycle can verify emails, calendar, notifications, and project status
  • Contextual: The agent has access to the entire main session history
  • Efficient: One API call instead of 5 separate cron jobs
  • Smart suppression: If nothing needs attention, the agent responds HEARTBEAT_OK and no message is delivered

Example HEARTBEAT.md:

# Heartbeat Checklist

- Scan urgent emails
- Check calendar for the next 2 hours
- If a background task is complete, summarize results
- Verify monitored services status
- If inactive for 8+ hours, perform a light check-in

OpenClaw Cron: Precision and Isolation

OpenClaw cron is a built-in scheduler in the Gateway. It persists jobs, wakes the agent at the right time, and can optionally deliver results to a chat.

Two execution modes:

  1. Main session (main): Injects a system event processed at the next heartbeat
  2. Isolated session (isolated): Runs a dedicated agent cycle in cron:<jobId>, without polluting the main history
# Recurring isolated job with Telegram delivery
openclaw cron add \
  --name "Daily Report" \
  --cron "0 8 * * *" \
  --tz "Europe/Paris" \
  --session isolated \
  --message "Generate the daily report: service status, key metrics, alerts." \
  --announce \
  --channel telegram \
  --to "-100123456789"

Decision Table: Heartbeat or Cron?

Use Case Recommended Why
Check emails every 30 min Heartbeat Combines with other checks
Daily report at 9 AM sharp Cron (isolated) Exact timing required
Calendar monitoring Heartbeat Suited for periodic checks
Weekly in-depth analysis Cron (isolated) Autonomous task, can use a different model
Reminder in 20 minutes Cron (main, --at) One-shot with precise timing
Clean temp files Heartbeat Piggyback on existing cycle
Nightly content generation Cron (isolated) Isolation + dedicated model

🛠️ Setting Up Your First AI Cron Jobs

Prerequisites

Before starting, ensure you have:

  • OpenClaw installed and the Gateway running
  • An LLM provider configured (Claude, GPT, or via OpenRouter)
  • A communication channel set up (Telegram, WhatsApp, Discord, etc.)

Job 1: One-Shot Reminder

The simplest. You want a reminder in 20 minutes:

openclaw cron add \
  --name "Meeting Reminder" \
  --at "20m" \
  --session main \
  --system-event "Reminder: The meeting starts in 10 minutes. Prepare a summary of points to discuss." \
  --wake now \
  --delete-after-run

The agent will receive this system event, and since it runs in the main session, it will have all the context of your recent conversations to prepare the summary.

Job 2: Recurring Morning Briefing

Every morning at 7:30 AM, a full report is generated and sent to Telegram:

openclaw cron add \
  --name "Morning Briefing" \
  --cron "30 7 * * *" \
  --tz "Europe/Paris" \
  --session isolated \
  --message "Generate the morning briefing: Paris weather, summary of important emails, today's calendar events, major tech news." \
  --model "opus" \
  --announce \
  --channel telegram \
  --to "-100123456789"

Why isolated? This job doesn’t need the main session’s context. It performs an autonomous task and delivers results directly.

Why --model opus? For a high-quality briefing, you can use a more powerful model. Isolated jobs allow choosing the model independently of the main session.

Job 3: Intelligent Monitoring

openclaw cron add \
  --name "Service Health Check" \
  --cron "*/15 * * * *" \
  --tz "UTC" \
  --session isolated \
  --message "Check service status: ping endpoints listed in /root/services.json. If a service is down, analyze recent logs and suggest a diagnosis. If all is OK, respond HEARTBEAT_OK." \
  --announce \
  --channel telegram \
  --to "-100123456789"

Here, the agent checks service status every 15 minutes. But unlike a classic monitoring script, it analyzes logs if there’s a problem and provides a natural language diagnosis.

Job 4: Weekly Review with High Thinking

openclaw cron add \
  --name "Weekly Review" \
  --cron "0 9 * * 1" \
  --tz "Europe/Paris" \
  --session isolated \
  --message "In-depth weekly analysis: project progress, key metrics, blockers, recommendations for the upcoming week." \
  --model "opus" \
  --thinking high \
  --announce \
  --channel telegram \
  --to "-100123456789"

The --thinking high flag enables extended reasoning, ideal for complex analyses requiring reflection.


📋 Concrete Automation Examples

Intelligent Website Monitoring

Instead of a simple ping, the AI agent can:

  1. Check response time
  2. Compare with history
  3. Detect trends (gradual degradation)
  4. Analyze page content (visual errors, missing content)
  5. Suggest corrective actions
openclaw cron add \
  --name "Website Monitor" \
  --cron "*/30 * * * *" \
  --session isolated \
  --message "Check https://my-site.com: response time, HTTP code, content. Compare with recent checks. Alert only if anomalies detected." \
  --announce \
  --channel telegram \
  --to "-100123456789"

Scheduled Content Generation

Every night, the agent prepares content for publishing:

openclaw cron add \
  --name "Night Content Worker" \
  --cron "0 2 * * *" \
  --tz "Europe/Paris" \
  --session isolated \
  --message "Check the pending articles database. For the next draft article, write the full content following the brief. Update status to need_review_human." \
  --model "opus" \
  --announce \
  --channel telegram \
  --to "-100123456789"

Smart Backups

Instead of blindly backing up every night:

openclaw cron add \
  --name "Smart Backup" \
  --cron "0 3 * * *" \
  --tz "Europe/Paris" \
  --session isolated \
  --message "Check files modified since the last backup. If significant changes exist, run an incremental backup. Verify backup integrity. Clean up backups older than 30 days. Summarize actions taken." \
  --announce

The agent decides if a backup is needed, verifies its integrity, and manages rotation—all in a single prompt.

Automatic Competitive Intelligence

openclaw cron add \
  --name "Competitor Watch" \
  --cron "0 10 * * 1,4" \
  --tz "Europe/Paris" \
  --session isolated \
  --message "Perform competitor monitoring: visit competitor sites listed in /root/competitors.json, detect price changes, new features, blog articles. Summarize key points." \
  --model "opus" \
  --announce \
  --channel telegram \
  --to "-100123456789"

⚡ Combining Heartbeat and Cron: The Optimal Configuration

The most effective setup uses both mechanisms together:

Heartbeat (every 30 min)
├── Scan urgent emails
├── Calendar check (next 2h)
├── Ongoing task status
└── Light check-in if inactive

Isolated Cron (precise timing)
├── 07:30 → Morning briefing (Opus)
├── 02:00 → Nightly content generation
├── */15  → Service monitoring
├── Mon 09:00 → Weekly review (Opus + high thinking)
└── One-shots → Reminders and deadlines

Full Configuration

{
  agents: {
    defaults: {
      heartbeat: {
        every: "30m",
        target: "telegram",
        to: "-100123456789",
        activeHours: {
          start: "07:00",
          end: "23:00",
          timezone: "Europe/Paris"
        }
      }
    }
  },
  cron: {
    enabled: true,
    maxConcurrentRuns: 1
  }
}

Associated HEARTBEAT.md:

# Heartbeat - Regular Checks

- Urgent emails: scan and alert if critical
- Calendar: events in the next 2 hours
- Ongoing tasks: progress and blockers
- If nothing urgent → HEARTBEAT_OK

💰 Cost Optimization

AI cron jobs consume tokens. Here’s how to optimize:

Strategy Estimated Savings How
Batching via heartbeat ~70% 1 heartbeat instead of 5 cron jobs
HEARTBEAT_OK suppression ~30% No delivery if nothing to report
Adapted model per job ~20% Use cheaper models for simple tasks
Active hours restriction ~40% Avoid unnecessary nighttime checks
Isolated sessions ~15% Prevents context pollution in main session