openclaw-home-pc/workspace/config/TASKS.md
2026-03-21 15:31:06 +08:00

162 lines
3.0 KiB
Markdown
Raw 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.

# 定时任务配置中心
> 📍 所有定时任务配置和管理都从这里开始
---
## 📋 当前任务列表
| 任务 | 描述 | 执行时间 | 状态 |
|------|------|----------|------|
| 天气预报 | 推送崇州市白头镇天气到企业微信 | 每天 08:00 | ✅ 已启用 |
---
## 🛠️ 管理命令
使用管理脚本(推荐):
```bash
cd /home/ubuntu/.openclaw/workspace/scripts
# 查看状态
./manage-tasks.sh status
# 手动测试(立即推送一次)
./manage-tasks.sh run
# 编辑脚本(修改 Webhook、地点等
./manage-tasks.sh edit
# 启动/停止定时任务
./manage-tasks.sh start
./manage-tasks.sh stop
# 修改配置后重载
./manage-tasks.sh reload
```
---
## 📁 文件位置
| 文件 | 路径 | 说明 |
|------|------|------|
| 天气脚本 | `scripts/weather-daily.sh` | 获取天气并推送 |
| 管理脚本 | `scripts/manage-tasks.sh` | 统一管理命令 |
| Service | `~/.config/systemd/user/daily-weather.service` | systemd 服务配置 |
| Timer | `~/.config/systemd/user/daily-weather.timer` | 定时触发器 |
| 日志 | `logs/weather-cron.log` | 执行日志 |
---
## ⚙️ 常见配置
### 修改推送时间
编辑 Timer 文件:
```bash
nano ~/.config/systemd/user/daily-weather.timer
```
修改 `OnCalendar` 行:
```ini
# 每天早上 7:30
OnCalendar=*-*-* 07:30:00
# 每天晚上 20:00
OnCalendar=*-*-* 20:00:00
# 每周一早上 9:00
OnCalendar=Mon *-*-* 09:00:00
```
保存后重载:
```bash
./manage-tasks.sh reload
```
### 修改推送地点
编辑天气脚本:
```bash
./manage-tasks.sh edit
```
修改经纬度坐标:
```bash
LAT="30.6" # 纬度
LON="103.6" # 经度
```
地点坐标查询https://www.latlong.net/
### 修改企业微信 Webhook
编辑天气脚本,找到 `WEBHOOK_URL` 行:
```bash
WEBHOOK_URL="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx"
```
---
## 🧪 测试
```bash
# 立即推送一次(测试配置是否正确)
./manage-tasks.sh run
# 查看最近日志
tail -20 logs/weather-cron.log
# 查看 systemd 日志
journalctl --user -u daily-weather.service -n 20
```
---
## 🔧 故障排查
**问题:定时任务不执行**
```bash
# 检查服务状态
systemctl --user status daily-weather.timer
# 查看日志
journalctl --user -u daily-weather.service -n 50
# 手动运行测试
./manage-tasks.sh run
```
**问题:推送失败**
1. 检查 Webhook URL 是否正确
2. 检查网络连接
3. 查看日志中的错误信息
**问题:修改配置后不生效**
```bash
# 一定要重载配置
./manage-tasks.sh reload
```
---
## 📚 systemd Timer 基础
| OnCalendar 格式 | 说明 |
|----------------|------|
| `*-*-* 08:00:00` | 每天 8:00 |
| `*-*-* 08:00:00` | 每天 8:00同上 |
| `Mon,Fri *-*-* 09:00:00` | 每周一、五 9:00 |
| `*-*-01 00:00:00` | 每月 1 号 0:00 |
| `hourly` | 每小时 |
| `daily` | 每天 |
| `weekly` | 每周 |
| `monthly` | 每月 |
完整文档https://www.freedesktop.org/software/systemd/man/systemd.time.html
---
🦐 皮皮虾维护 · 有问题随时找我