OpenCode 中文实战课源码与内容仓库,提供一课一页的学习资源,覆盖从入门到实战工作流。适用于运维团队,帮助快速掌握AI工具集成和自动化操作。支持Shell脚本,适用于中级用户,与Claude代理兼容。
git clone https://github.com/vbgate/learn-opencode.githttps://learnopencode.com
1. **下载 OpenCode 仓库**: 从 GitHub 仓库(如 `opencode-cn/learn-opencode`)下载对应的学习资源和脚本模板,或直接克隆仓库: ```bash git clone https://github.com/opencode-cn/learn-opencode.git cd learn-opencode/shell-automation ``` 2. **选择或定制脚本**: 根据团队需求,选择已有的自动化脚本(如日志清理、配置备份)或基于模板创建新脚本。确保脚本包含以下核心功能: - 环境变量配置(如日志目录、保留天数、通知邮箱)。 - 错误处理和日志记录机制。 - AI 工具 API 调用(如 Claude 代理)。 3. **配置 AI 工具集成**: 在脚本中配置 AI 工具的 API 地址和调用方式。例如,使用 `curl` 或 Python 发送 HTTP 请求。确保 AI 工具已部署并可访问。 4. **测试和部署**: 在测试环境中运行脚本,验证其功能和错误处理。成功后,将脚本部署到生产环境,并设置定时任务(如 `cron`)定期执行。 5. **监控和优化**: 使用 AI 工具生成的报告监控脚本执行情况,并根据实际需求调整脚本逻辑(如添加更多监控指标或优化清理策略)。 **提示**: - 使用 `set -e` 确保脚本在出错时立即退出。 - 为脚本添加 `--help` 参数,提供使用说明。 - 定期审查 AI 工具的输出,确保其建议或报告符合团队需求。
Quickly set up an AI programming environment for personal or professional projects.
Automate content creation for blogs, social media, or marketing campaigns using AI tools.
Enhance coding efficiency by integrating AI for debugging and code refactoring.
Streamline data processing tasks with automated scripts powered by AI.
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/vbgate/learn-opencodeCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
请基于 OpenCode 中文实战课源码与内容仓库,为 [TEAM_NAME] 运维团队生成一个可执行的自动化脚本模板。要求: 1. 使用 Shell 脚本实现 [SPECIFIC_TASK],如日志清理、配置备份或监控告警。 2. 集成 [AI_TOOL_NAME] 的 API 调用,如 Claude 代理或其他 AI 工具。 3. 包含错误处理、日志记录和通知机制(如邮件或钉钉)。 4. 确保脚本可在 Linux 环境中直接运行,并提供详细的注释。 示例用法: ```bash ./automation_script.sh --task log_cleanup --days 7 --notify admin@example.com ```
### 自动化日志清理脚本示例
**脚本名称**: `log_cleanup_automation.sh`
**版本**: v1.0
**适用场景**: 运维团队定期清理应用日志,避免磁盘空间被占满。
```bash
#!/bin/bash
# 配置变量
LOG_DIR="/var/log/myapp"
RETENTION_DAYS=7
NOTIFY_EMAIL="ops-team@example.com"
AI_TOOL_API="http://localhost:8080/api/claude-agent"
# 日志记录函数
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> /var/log/automation.log
}
# 错误处理函数
handle_error() {
log "ERROR: $1"
curl -X POST -H "Content-Type: application/json" -d "{\"message\": \"日志清理失败: $1\"}" "$AI_TOOL_API"
exit 1
}
# 检查日志目录是否存在
if [ ! -d "$LOG_DIR" ]; then
handle_error "日志目录 $LOG_DIR 不存在"
fi
# 删除超过保留天数的日志文件
log "开始清理日志目录: $LOG_DIR"
find "$LOG_DIR" -name "*.log" -type f -mtime +$RETENTION_DAYS -exec rm -f {} \; 2>/dev/null
if [ $? -eq 0 ]; then
log "成功清理日志文件"
# 调用 AI 工具生成清理报告
curl -X POST -H "Content-Type: application/json" -d "{\"task\": \"log_cleanup\", \"details\": \"已清理 $RETENTION_DAYS 天前的日志\"}" "$AI_TOOL_API"
else
handle_error "日志清理过程中出现错误"
fi
# 发送通知邮件
if [ -n "$NOTIFY_EMAIL" ]; then
echo "日志清理完成" | mail -s "[自动化脚本] 日志清理成功" "$NOTIFY_EMAIL"
fi
log "脚本执行完成"
```
**执行结果示例**:
```
$ ./log_cleanup_automation.sh
[2024-05-20 14:30:45] 开始清理日志目录: /var/log/myapp
[2024-05-20 14:30:46] 成功清理日志文件
[2024-05-20 14:30:46] 脚本执行完成
```
**AI 工具调用结果**:
```json
{
"response": "已成功清理 /var/log/myapp 目录下超过 7 天的日志文件。建议定期检查磁盘空间使用情况。",
"status": "success"
}
```Cloud ETL platform for non-technical data integration
IronCalc is a spreadsheet engine and ecosystem
Get more done every day with Microsoft Teams – powered by AI
Customer feedback management made simple
Enterprise workflow automation and service management platform
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan