完善 weekly-report 使用说明:添加定时任务配置指南
涵盖凭证安全存储、执行脚本写法、Windows Task Scheduler 和 Linux crontab 配置 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
176f93614b
commit
7ff805ca68
@ -92,6 +92,85 @@ Claude 会自动执行以下流程:
|
|||||||
5. 生成项目整体进度报告
|
5. 生成项目整体进度报告
|
||||||
6. 发送 HTML 格式邮件到 `recipients` 列表
|
6. 发送 HTML 格式邮件到 `recipients` 列表
|
||||||
|
|
||||||
|
## 定时自动发送(Cron)
|
||||||
|
|
||||||
|
通过 `claude -p` 可以以非交互模式运行技能,配合定时任务实现每周自动发送。
|
||||||
|
|
||||||
|
### 安全存储凭证
|
||||||
|
|
||||||
|
**不要**把密码直接写在脚本里,应单独存放在权限受限的凭证文件中:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 创建凭证文件(只存在于本机,不入 git)
|
||||||
|
cat > ~/.ieslab_credentials << 'EOF'
|
||||||
|
export SMTP_USER=your@email.com
|
||||||
|
export SMTP_PASSWORD=your-auth-code
|
||||||
|
export GITEA_TOKEN=your-gitea-token
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 限制只有当前用户可读
|
||||||
|
chmod 600 ~/.ieslab_credentials
|
||||||
|
```
|
||||||
|
|
||||||
|
### 创建执行脚本
|
||||||
|
|
||||||
|
新建 `~/weekly_report.sh`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# 加载凭证(敏感信息在此文件中,不在本脚本里)
|
||||||
|
source ~/.ieslab_credentials
|
||||||
|
|
||||||
|
# 切换到目标项目目录
|
||||||
|
cd /path/to/your-project
|
||||||
|
|
||||||
|
# 以非交互模式运行技能
|
||||||
|
claude -p "/weekly-report"
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod +x ~/weekly_report.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
> `claude -p` 是 Claude Code 的非交互模式,执行完成后自动退出,适合在定时任务中使用。
|
||||||
|
|
||||||
|
### Windows 定时任务(Task Scheduler)
|
||||||
|
|
||||||
|
Windows 没有 cron,使用"任务计划程序"代替:
|
||||||
|
|
||||||
|
1. 开始菜单搜索「任务计划程序」→「创建基本任务」
|
||||||
|
2. 触发器:选择「每周」,设置具体时间(如每周五 18:00)
|
||||||
|
3. 操作:选择「启动程序」
|
||||||
|
- 程序:`C:\Program Files\Git\bin\bash.exe`
|
||||||
|
- 参数:`-l -c "/c/Users/你的用户名/weekly_report.sh"`
|
||||||
|
4. 在「条件」中取消勾选「只在使用交流电源时运行」
|
||||||
|
|
||||||
|
### Linux / Mac(crontab)
|
||||||
|
|
||||||
|
如果在 Linux 服务器上运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
crontab -e
|
||||||
|
```
|
||||||
|
|
||||||
|
添加一行(每周五 18:00 执行):
|
||||||
|
|
||||||
|
```
|
||||||
|
0 18 * * 5 /bin/bash ~/weekly_report.sh >> ~/weekly_report.log 2>&1
|
||||||
|
```
|
||||||
|
|
||||||
|
`>> ~/weekly_report.log 2>&1` 会把输出和错误都记录到日志文件,方便排查问题。
|
||||||
|
|
||||||
|
### 注意事项
|
||||||
|
|
||||||
|
- 凭证文件 `~/.ieslab_credentials` 必须 `chmod 600`,且**绝不能提交到 git**
|
||||||
|
- 脚本中只有 `source ~/.ieslab_credentials`,密码本身不出现在脚本里
|
||||||
|
- 定时任务的运行环境可能缺少 `claude` 的 PATH,如遇「命令未找到」错误,将 `claude` 替换为绝对路径(可用 `which claude` 查询)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 常见问题
|
## 常见问题
|
||||||
|
|
||||||
**Q:发送失败,提示认证错误**
|
**Q:发送失败,提示认证错误**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user