Automate Anything with Cron
Automate Everything with Cron — easy-to-understand guide based on official docs
Automate Anything with Cron
If you’ve ever wished your computer could just do things for you on a schedule, you’re in the right place. We already covered the basics of cron jobs in the daily briefing bot tutorial, but today we’re going deeper. Here are five real-world automation patterns you can steal for your own workflows.
The Golden Rule: Self-Contained Prompts
Before we dive in, there’s one concept you need to understand: cron jobs run in fresh agent sessions. Your agent has zero memory of your current chat. That means every prompt must be completely self-contained — include everything the agent needs to know, from the exact commands to run to the format you want back.
Also, a quick tip: if you don’t need the LLM at all (say, you just want a script to run and send a message), you have two zero-token options. You can use script-only cron jobs where the script produces the exact message, or use hermes send to pipe output from an already-running script straight to Telegram or Discord. Ask Hermes in chat to set these up — the cronjob tool knows when to skip the agent.
Pattern 1: Website Change Monitor
Want to know the moment a competitor updates their pricing page? This pattern uses a Python script to do the heavy lifting (fetching and diffing), while the agent handles the reasoning (is this change interesting?).
First, create a monitoring script:
mkdir -p ~/.hermes/scripts
import hashlib, json, os, urllib.request
URL = "https://example.com/pricing"
STATE_FILE = os.path.expanduser("~/.hermes/scripts/.watch-site-state.json")
# Fetch current content
req = urllib.request.Request(URL, headers={"User-Agent": "Hermes-Monitor/1.0"})
content = urllib.request.urlopen(req, timeout=30).read().decode()
current_hash = hashlib.sha256(content.encode()).hexdigest()
# Load previous state
prev_hash = None
if os.path.exists(STATE_FILE):
with open(STATE_FILE) as f:
prev_hash = json.load(f).get("hash")
# Save current state
with open(STATE_FILE, "w") as f:
json.dump({"hash": current_hash, "url": URL}, f)
# Output for the agent
if prev_hash and prev_hash != current_hash:
print(f"CHANGE DETECTED on {URL}")
print(f"Previous hash: {prev_hash}")
print(f"Current hash: {current_hash}")
print(f"\nCurrent content (first 2000 chars):\n{content[:2000]}")
else:
print("NO_CHANGE")
Now set up the cron job:
/cron add "every 1h" "If the script output says CHANGE DETECTED, summarize what changed on the page and why it might matter. If it says NO_CHANGE, respond with just [SILENT]." --script ~/.hermes/scripts/watch-site.py --name "Pricing monitor" --deliver telegram
The [SILENT] trick: For monitoring jobs, tell the agent to respond with only [SILENT] when nothing changed. Cron delivery treats this as the quiet marker, so you only get notified when something actually happens. No spam during quiet hours.
Pattern 2: Weekly Report
Compile information from multiple sources into a formatted summary. This runs every Monday at 9 AM:
/cron add "0 9 * * 1" "Generate a weekly report covering:
1. Search the web for the top 5 AI news stories from the past week
2. Search GitHub for trending repositories in the 'machine-learning' topic
3. Check Hacker News for the most discussed AI/ML posts
Format as a clean summary with sections for each source. Include links.
Keep it under 500 words — highlight only what matters." --name "Weekly AI digest" --deliver telegram
From the CLI, it looks like this:
hermes cron create "0 9 * * 1" \
"Generate a weekly report covering the top AI news, trending ML GitHub repos, and most-discussed HN posts. Format with sections, include links, keep under 500 words." \
--name "Weekly AI digest" \
--deliver telegram
The 0 9 * * 1 is standard cron syntax: minute 0, hour 9, any day of month, any month, Monday.
Pattern 3: GitHub Repository Watcher
Keep tabs on a repo for new issues, PRs, or releases:
/cron add "every 6h" "Check the GitHub repository NousResearch/hermes-agent for:
- New issues opened in the last 6 hours
- New PRs opened or merged in the last 6 hours
- Any new releases
Use the terminal to run gh commands:
gh issue list --repo NousResearch/hermes-agent --state open --json number,title,author,createdAt --limit 10
gh pr list --repo NousResearch/hermes-agent --state all --json number,title,author,createdAt,mergedAt --limit 10
Filter to only items from the last 6 hours. If nothing new, respond with [SILENT].
Otherwise, provide a concise summary of the activity." --name "Repo watcher" --deliver discord
Notice how the prompt includes the exact gh commands. The cron agent has no conversation history — spell everything out. (Persistent memory does load, so durable preferences saved to MEMORY.md carry over, but don’t rely on it for job-critical details.)
Pattern 4: Data Collection Pipeline
Scrape data at regular intervals, save to files, and detect trends over time. This combines a script (for collection) with the agent (for analysis):
import json, os, urllib.request
from datetime import datetime
DATA_DIR = os.path.expanduser("~/.hermes/data/prices")
os.makedirs(DATA_DIR, exist_ok=True)
# Fetch current data (example: crypto prices)
url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum&vs_currencies=usd"
data = json.loads(urllib.request.urlopen(url, timeout=30).read())
# Append to history file
entry = {"timestamp": datetime.now().isoformat(), "prices": data}
history_file = os.path.join(DATA_DIR, "history.jsonl")
with open(history_file, "a") as f:
f.write(json.dumps(entry) + "\n")
# Print summary for the agent
print(f"Collected prices: BTC ${data['bitcoin']['usd']}, ETH ${data['ethereum']['usd']}")
print(f"History file: {history_file}")
Then set up a cron job that runs the script and asks the agent to analyze trends:
/cron add "every 30m" "Run the script, then analyze the price history in ~/.hermes/data/prices/history.jsonl. If you notice a significant trend (more than 5% change in the last 24 hours), summarize it. Otherwise, respond with [SILENT]." --script ~/.hermes/scripts/collect-prices.py --name "Price tracker" --deliver telegram
Go Forth and Automate
These five patterns cover the most common automation needs — monitoring, reporting, watching, and collecting. The key is remembering that scripts handle the mechanical work, and the agent handles the reasoning. Mix and match these ideas to build your own automations. Happy automating!
📖 Official Docs
This article is based on the official Hermes Agent documentation:Official docs › guides/automate-with-cron