进一步简化定时任务:直接一行 crontab,无需独立脚本文件
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2f5a9f7035
commit
002522a540
@ -110,23 +110,15 @@ Claude 会自动执行以下流程:
|
||||
|
||||
## 定时自动发送(Cron)
|
||||
|
||||
通过 `claude -p` 非交互模式配合定时任务实现每周自动发送。
|
||||
### Linux / Mac
|
||||
|
||||
新建 `~/weekly_report.sh`,把密码直接写在脚本里,设置好权限确保只有自己可读:
|
||||
`crontab -e` 添加一行(每周五 18:00):
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
export SMTP_USER=your@email.com
|
||||
export SMTP_PASSWORD=your-auth-code
|
||||
export GITEA_TOKEN=your-gitea-token # 私有仓库才需要
|
||||
|
||||
cd /path/to/your-project
|
||||
claude -p "/weekly-report"
|
||||
```
|
||||
0 18 * * 5 cd /path/to/your-project && SMTP_USER=xxx SMTP_PASSWORD=xxx claude -p "/weekly-report" >> ~/weekly_report.log 2>&1
|
||||
```
|
||||
|
||||
```bash
|
||||
chmod 600 ~/weekly_report.sh
|
||||
```
|
||||
crontab 文件权限默认仅限当前用户,密码写在里面是安全的。
|
||||
|
||||
### Windows(任务计划程序)
|
||||
|
||||
@ -134,15 +126,7 @@ chmod 600 ~/weekly_report.sh
|
||||
2. 触发器:每周,设置具体时间(如每周五 18:00)
|
||||
3. 操作:启动程序
|
||||
- 程序:`C:\Program Files\Git\bin\bash.exe`
|
||||
- 参数:`-l -c "/c/Users/你的用户名/weekly_report.sh"`
|
||||
|
||||
### Linux / Mac(crontab)
|
||||
|
||||
```bash
|
||||
crontab -e
|
||||
# 添加(每周五 18:00):
|
||||
0 18 * * 5 /bin/bash ~/weekly_report.sh >> ~/weekly_report.log 2>&1
|
||||
```
|
||||
- 参数:`-l -c "cd /e/your-project && SMTP_USER=xxx SMTP_PASSWORD=xxx claude -p '/weekly-report'"`
|
||||
|
||||
> 如遇「命令未找到」,将 `claude` 替换为绝对路径(用 `which claude` 查询)。
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user