VPS chạy Hermes Agent không nên ngồi không - nó nên làm việc khi bạn ngủ. Hermes có cron built-in (không cần tự config crontab Linux): schedule task chạy hằng đêm, hằng giờ, hằng tuần, có log + retry + notify khi fail. Bài này dạy bạn setup pipeline automation hằng đêm trên VPS từ A đến Z.
Hermes cron vs system cron - chọn cái nào
VPS Linux có sẵn cron chạy hàng chục năm rồi - vẫn ổn. Nhưng Hermes có scheduler riêng tích hợp sâu vào agent, hơn hẳn ở 3 điểm:
| Aspect | System cron | Hermes cron |
|---|---|---|
| Truy cập skill/tool | Phải invoke hermes CLI | Native, gọi trực tiếp |
| Context giữa runs | Stateless, mỗi lần fresh | Có memory persistent |
| Log + retry | Phải tự code | Built-in retry, structured log |
| Notify khi fail | MAILTO, hoặc custom | Telegram/Discord auto |
| Sửa lịch | Edit crontab | Command trong Hermes |
Quy tắc đơn giản: task có liên quan đến agent (gọi skill, browser, LLM) -> Hermes cron. Task pure system (backup file, rotate log) -> system cron.
Cron syntax - vẫn là 5 field cổ điển
Hermes giữ syntax cron chuẩn:
* * * * *| | | | || | | | +-- day of week (0-6, Sun=0)| | | +---- month (1-12)| | +------ day of month (1-31)| +-------- hour (0-23)+---------- minute (0-59)Một số shortcut tiện:
| Shortcut | Tương đương |
|---|---|
| @hourly | 0 * * * * |
| @daily | 0 0 * * * |
| @weekly | 0 0 * * 0 |
| @monthly | 0 0 1 * * |
| @every 15m | */15 * * * * |
Add task lịch đầu tiên
Trong Hermes, gõ:
/cron addHoặc nói tự nhiên:
You: tạo task chạy mỗi sáng 7h: search Google tin tức "AI agent 2026",tóm tắt top 5, gửi Telegram chat 123456789 Hermes: [cron.add schedule="0 7 * * *" name="daily-ai-news" action="search 'AI agent 2026' news, summarize top 5, send telegram 123456789"]OK, task "daily-ai-news" đã lên lịch. Next run: 2026-05-30 07:00 +07.List tất cả task:
You: /cron list Hermes: 3 scheduled tasks:1. daily-ai-news @ 0 7 * * * next: 2026-05-30 07:002. weekly-shop-report @ 0 8 * * 1 next: 2026-06-01 08:003. hourly-uptime @ 0 * * * * next: 2026-05-29 16:003 mẫu task thực tế
Task 1: Daily news digest 7h sáng
Mục tiêu: 7h sáng dậy có sẵn bản tin AI/tech tóm tắt trong Telegram.
You: cron @daily lúc 7h:- search Google "AI agent latest news"- search x.com "Hermes Agent" trong 24h- tổng hợp 10 highlight quan trọng- format markdown- gửi telegram chat_id mình Hermes: [cron.add schedule="0 7 * * *" name="daily-tech-digest" action=""" 1. web_search('AI agent latest news', limit=10) 2. x_search('Hermes Agent', since='24h', limit=20) 3. merge + dedupe 4. summarize top 10 với LLM, format markdown 5. telegram.send_message chat_id=$DEFAULT_CHAT_ID text=summary """]OK.Task 2: Weekly scrape report thứ 2
Mỗi thứ 2 lúc 8h, crawl top SP đối thủ, so giá với shop bạn, gửi báo cáo:
You: cron 0 8 * * 1:- dùng rotate_proxy lấy 1 IP VN- scrape 50 SP top-seller của shop san-s.example/shop/123- so với data SP của mình từ shopify-product-export.csv- highlight SP nào competitor rẻ hơn 10% hoặc đắt hơn 10%- export ra reports/competitor-{date}.csv- gửi file qua telegram Hermes: [cron.add name="weekly-competitor-report" schedule="0 8 * * 1" ...]Task 3: Hourly health check
Check VPS health mỗi giờ, alert khi load > 5 hoặc disk > 80%:
You: cron mỗi giờ:- chạy shell uptime, df -h, free -m- parse load average, disk usage, ram free- nếu load > 5 hoặc disk > 80% hoặc ram free < 500MB- alert Telegram với chi tiết- ngược lại không gửi gì (silent OK) Hermes: [cron.add name="hourly-health" schedule="0 * * * *" ...]Mẹo: Đặt cron silent-on-success - chỉ alert khi có vấn đề. Không ai muốn 24 notification "OK" mỗi ngày. Tin nhắn càng ít, càng có giá trị.
Log + retry + error handling
Mỗi task chạy ghi log vào ~/.hermes/logs/cron/{task_name}-{timestamp}.log. Format:
[2026-05-29 07:00:01] START daily-tech-digest[2026-05-29 07:00:02] action: web_search[2026-05-29 07:00:05] action: x_search ... OK[2026-05-29 07:00:08] action: summarize ... OK[2026-05-29 07:00:09] action: telegram.send ... OK[2026-05-29 07:00:10] DONE in 9.2sKhi task fail (network drop, LLM timeout, skill error), Hermes retry theo policy:
[cron.retry_policy]max_attempts = 3backoff = "exponential" # 30s, 60s, 120son_final_failure = "notify_telegram"Sau 3 lần fail liên tiếp, agent gửi Telegram alert kèm log trace.
Concurrency - 2 task trùng giờ
Nếu 2 task khác nhau cùng schedule 7h sáng, Hermes mặc định chạy parallel (mỗi task 1 process/thread). Trong môi trường VPS giới hạn RAM, có khi muốn nó tuần tự:
[cron]max_concurrent = 2 # tối đa 2 task chạy cùng lúcqueue_when_full = true # task thứ 3 vào queue đợiTăng max_concurrent nếu VPS mạnh và task không đụng resource chung (browser, port, file lock).
Dynamic schedule - lịch không phải hard-code
Đôi khi bạn muốn lịch điều chỉnh theo data. Ví dụ: "chạy report vào thứ 6 cuối tháng". Hermes hỗ trợ Python lambda trong schedule:
[cron.task.monthly-report]type = "dynamic"should_run = """from datetime import date, timedeltatoday = date.today()# Friday of last week of monthtomorrow = today + timedelta(days=1)return today.weekday() == 4 and tomorrow.month != today.month"""check_every = "@hourly"action = "generate monthly report and email"Cách này linh hoạt hơn cron syntax với rule phức tạp (ngày làm việc, holiday, etc).
Sửa và xoá task
# Pause task tạm thời/cron pause daily-tech-digest # Resume/cron resume daily-tech-digest # Sửa schedule/cron edit daily-tech-digest schedule="0 8 * * *" # Run thử ngay không chờ tới giờ/cron run-now daily-tech-digest # Xoá hẳn/cron delete daily-tech-digestRun-now là cách test workflow trước khi tin tưởng nó chạy đêm. Luôn run-now 2-3 lần trước khi go-live.
Timezone - lỗi hay gặp nhất
VPS thuê có khi default UTC, không phải giờ VN. Cron "0 7 * * *" thành 7h sáng UTC = 14h VN. Set timezone:
Cách 1 - system level:
sudo timedatectl set-timezone Asia/Ho_Chi_Minhdate # check# Fri May 29 15:30:00 +07 2026Cách 2 - Hermes config:
[cron]timezone = "Asia/Ho_Chi_Minh"Cách 2 ưu tiên hơn vì rõ ràng và không phụ thuộc system.
Lưu ý: Daylight saving (DST) ở VN không tồn tại nhưng nếu deploy multi-region, cron có thể nhảy 1 giờ vào mùa hè. Luôn set explicit timezone trong config.
Persist qua reboot - systemd
Cron của Hermes chỉ chạy khi Hermes process còn sống. VPS reboot -> Hermes tắt -> cron dừng. Giải pháp: systemd auto-restart.
File /etc/systemd/system/hermes.service (đã đề cập trong bài Telegram bot):
[Service]Type=simpleUser=userEnvironmentFile=/home/user/.hermes/.envExecStart=/home/user/.hermes/venv/bin/hermes --headless --enable-cronRestart=alwaysRestartSec=10Quan trọng: flag để scheduler kích hoạt khi không có terminal interactive.
Theo dõi và debug
Hermes có dashboard log đơn giản:
# Tail log realtimehermes cron logs --follow # Xem run history của 1 taskhermes cron history daily-tech-digest --last 10 # Stats theo taskhermes cron stats# Output:# task runs success fail avg_duration# daily-tech-digest 30 29 1 9.4s# weekly-shop-report 4 4 0 45.2s# hourly-uptime 720 720 0 1.1sKhi 1 task fail rate > 5%, đào log để hiểu nguyên nhân. Network drop hay LLM rate-limit hay skill bug.
Bandwidth + cost - tránh ngạc nhiên
Task hằng đêm có thể đốt tiền nếu không tính trước:
- LLM call: 1 task summary = 5k-20k token = 1-5 cent. 30 ngày x 30 task = $30-150/tháng
- Bandwidth scrape: 100 trang/đêm = ~10MB. 30 ngày = 300MB
- Proxy: Mỗi cron task qua proxy IPv4 dedicated không tốn thêm (flat fee)
- Storage log: ~10MB log/tháng, rotate sau 30 ngày
Tính trước rồi xem có nên scale lên VPS lớn không.
VPS đủ cho cron 24/7
Cron tự nó nhẹ. Nặng là task nó chạy. Quy tắc:
| Số task hằng ngày | VPS |
|---|---|
| 1-3 task đơn giản (text, search) | VPS 50 (4vCPU/4GB) 639k |
| 5-10 task, có browser | VPS 80 (6vCPU/6GB) 999k |
| 20+ task, scrape liên tục | VPS lớn hơn + proxy pool |
Đọc thêm cách chọn ở bài VPS cho vibe coder. Nếu bạn chưa cài Hermes, bắt đầu từ hướng dẫn cài Hermes + gắn proxy.
Checklist deploy cron production
- Timezone set Asia/Ho_Chi_Minh trong config
- Systemd service active với
- Retry policy max 3, exponential backoff
- Notify channel (Telegram/Discord) cho fail
- Log rotation 30 ngày để không full disk
- Task quan trọng đã
/cron run-nowtest thành công - Concurrency limit phù hợp RAM VPS
- Silent-on-success cho task định kỳ
- Health-check task ít nhất @hourly để biết khi VPS chết
