115 lines
2.4 KiB
Markdown
115 lines
2.4 KiB
Markdown
# 天气预报定时任务配置指南
|
||
|
||
## ✅ 已完成
|
||
|
||
1. 脚本已创建:`/home/ubuntu/.openclaw/workspace/scripts/weather-daily.sh`
|
||
2. 脚本已授权:可执行权限已设置
|
||
3. 日志目录已创建:`/home/ubuntu/.openclaw/workspace/logs/`
|
||
|
||
## ⚠️ 需要配置
|
||
|
||
### 1. 设置企业微信 Webhook
|
||
|
||
编辑脚本,将 Webhook URL 填入:
|
||
|
||
```bash
|
||
nano /home/ubuntu/.openclaw/workspace/scripts/weather-daily.sh
|
||
```
|
||
|
||
找到这一行:
|
||
```bash
|
||
WEBHOOK_URL="YOUR_WEBHOOK_URL_HERE"
|
||
```
|
||
|
||
替换为你的企业微信群机器人 Webhook URL(类似 `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx`)
|
||
|
||
**获取 Webhook 的方法:**
|
||
1. 在企业微信群里点击右上角「…」
|
||
2. 找到「群机器人」→「添加机器人」
|
||
3. 创建新机器人,复制 Webhook URL
|
||
|
||
### 2. 安装并配置定时任务
|
||
|
||
由于系统未安装 cron,需要手动配置:
|
||
|
||
**方法 A:安装 cron(推荐)**
|
||
```bash
|
||
sudo apt-get update
|
||
sudo apt-get install -y cron
|
||
sudo systemctl enable cron
|
||
sudo systemctl start cron
|
||
|
||
# 添加定时任务(每天早上 8:00 执行)
|
||
(crontab -l 2>/dev/null; echo "0 8 * * * /home/ubuntu/.openclaw/workspace/scripts/weather-daily.sh >> /home/ubuntu/.openclaw/workspace/logs/weather-cron.log 2>&1") | crontab -
|
||
|
||
# 验证
|
||
crontab -l
|
||
```
|
||
|
||
**方法 B:使用 systemd timer**
|
||
```bash
|
||
# 创建 service 文件
|
||
sudo nano /etc/systemd/system/weather-daily.service
|
||
```
|
||
|
||
内容:
|
||
```ini
|
||
[Unit]
|
||
Description=Daily Weather Report
|
||
|
||
[Service]
|
||
Type=oneshot
|
||
ExecStart=/home/ubuntu/.openclaw/workspace/scripts/weather-daily.sh
|
||
User=ubuntu
|
||
WorkingDirectory=/home/ubuntu/.openclaw/workspace
|
||
```
|
||
|
||
```bash
|
||
# 创建 timer 文件
|
||
sudo nano /etc/systemd/system/weather-daily.timer
|
||
```
|
||
|
||
内容:
|
||
```ini
|
||
[Unit]
|
||
Description=Run weather report daily at 8:00
|
||
|
||
[Timer]
|
||
OnCalendar=*-*-* 08:00:00
|
||
Persistent=true
|
||
|
||
[Install]
|
||
WantedBy=timers.target
|
||
```
|
||
|
||
```bash
|
||
# 启用并启动
|
||
sudo systemctl daemon-reload
|
||
sudo systemctl enable weather-daily.timer
|
||
sudo systemctl start weather-daily.timer
|
||
|
||
# 验证
|
||
systemctl list-timers
|
||
```
|
||
|
||
## 🧪 测试脚本
|
||
|
||
手动运行测试:
|
||
```bash
|
||
bash /home/ubuntu/.openclaw/workspace/scripts/weather-daily.sh
|
||
```
|
||
|
||
查看日志:
|
||
```bash
|
||
tail -f /home/ubuntu/.openclaw/workspace/logs/weather-cron.log
|
||
```
|
||
|
||
## 📋 推送时间
|
||
|
||
- **默认时间**:每天早上 8:00(Asia/Shanghai 时区)
|
||
- **修改时间**:编辑 crontab 或 timer 配置
|
||
|
||
---
|
||
|
||
🦐 配置完成后,皮皮虾每天准时为你推送天气预报!
|