openclaw-home-pc/workspace/knowledge/work/scheduled-task-check-procedure.md
2026-03-21 15:31:06 +08:00

159 lines
3.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 定时任务检查流程
> **创建日期**: 2026-03-18
> **适用场景**: 检查系统定时任务、排查重复任务、清理冗余配置
> **来源**: 欢欢助理与欢哥的对话记录
---
## 📋 检查目标
1. 查看 OpenClaw 内置 Cron 任务
2. 检查系统级 Crontab
3. 检查 Systemd Timers
4. 排查重复任务
---
## 🔍 检查步骤
### 步骤 1: 检查 OpenClaw Cron 任务
```bash
# 使用 OpenClaw cron 工具
openclaw cron list --includeDisabled
```
**预期结果**:
- 返回 JSON 格式的任务列表
- 空列表表示无内置任务
---
### 步骤 2: 检查系统 Crontab
```bash
# 查看当前用户的 crontab
crontab -l
# 查看系统级 cron 配置
cat /etc/cron.d/* 2>/dev/null
# 搜索特定任务的 cron 配置
grep -r "任务关键词" /etc/cron* 2>/dev/null
```
**预期结果**:
- `no crontab for user` 表示无用户级任务
- 具体任务列表表示已配置
---
### 步骤 3: 检查 Systemd Timers
```bash
# 列出所有 timers包括未激活的
systemctl list-timers --all
# 筛选特定服务的 timer
systemctl list-timers | grep "关键词"
```
**常见系统 Timer**:
| Timer | 用途 |
|-------|------|
| `apt-daily.timer` | 系统包更新 |
| `logrotate.timer` | 日志轮转 |
| `fwupd-refresh.timer` | 固件更新 |
| `fstrim.timer` | SSD 修剪 |
---
### 步骤 4: 检查后台进程
```bash
# 搜索特定任务的进程
ps aux | grep -E "(关键词)" | grep -v grep
# 查看进程的详细信息
ps -ef | grep "进程名"
```
---
### 步骤 5: 检查脚本文件
```bash
# 查找相关脚本
find /path/to/search -name "*关键词*" 2>/dev/null
# 查看工作区脚本
ls -la ~/.openclaw/workspace/scripts/
```
---
## 📊 检查结果记录模板
```markdown
### 检查日期YYYY-MM-DD
| 检查项 | 状态 | 备注 |
|--------|------|------|
| OpenClaw Cron | ✅ 空 / ⚠️ 有任务 | 详情... |
| 系统 Crontab | ✅ 空 / ⚠️ 有任务 | 详情... |
| Systemd Timers | ✅ 仅系统默认 / ⚠️ 有自定义 | 详情... |
| 后台进程 | ✅ 正常 / ⚠️ 异常 | 详情... |
**结论**: 无重复任务 / 发现重复任务 XXX
```
---
## 🧹 清理重复任务
### 删除 Crontab 任务
```bash
# 编辑 crontab
crontab -e
# 删除指定行,保存退出
```
### 禁用 Systemd Timer
```bash
# 停止 timer
sudo systemctl stop xxx.timer
# 禁用 timer
sudo systemctl disable xxx.timer
```
### 删除 OpenClaw Cron 任务
```bash
# 使用 OpenClaw 工具
openclaw cron remove --job-id "任务 ID"
```
---
## ⚠️ 注意事项
1. **备份优先**: 删除前先备份配置
2. **确认权限**: 系统级任务需要 sudo 权限
3. **验证效果**: 删除后重新检查确认
4. **记录变更**: 更新 MEMORY.md 或当日日志
---
## 💡 经验总结
1. **OpenClaw Cron** 优先于系统 crontab更易管理
2. **Systemd Timers** 适合精确时间的任务
3. **心跳任务** 适合周期性检查(如邮件、日历)
4. **定期审查** 建议每月检查一次定时任务
---
*本文档由欢欢助理整理,实际操作前请确认权限。*