mcpField
O
os-scripting

os-scripting

github.com/sickn33开发48.7k79 次安装今天更新
代码仓库

关于 os-scripting

os-scripting 是面向 Linux、macOS 和 Windows 的系统排障、Shell 脚本与管理工作流技能包,供开发和系统管理任务使用。它可按需组织环境检查、调试、测试和自动化阶段,并强调验证与安全边界。

主要功能

  1. 01环境与资源检查
  2. 02使用 ShellCheck 分析脚本
  3. 03脚本调试与开发
  4. 04Bats 测试与质量检查
  5. 05系统排障与任务自动化

适用场景

  1. 01诊断系统性能或服务故障
  2. 02检查、调试和测试 Shell 脚本
  3. 03编写系统维护脚本
  4. 04安排定期管理任务

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/sickn33/agentic-awesome-skills --skill os-scripting

安装后在 Claude Code 中输入/os-scripting确认已加载。

详细介绍

原文在翻译后有更新,译文可能不是最新。

OS/Shell 脚本疑难排查工作流包

概述

用于跨 Linux、macOS 和 Windows 进行操作系统疑难排查、Shell 脚本编写和系统管理的综合工作流。此包编排了用于调试系统问题、创建健壮脚本以及自动化管理任务的技能。

何时使用此工作流

在以下情况下使用此工作流:

  • 调试 Shell 脚本错误
  • 创建可用于生产环境的 bash 脚本
  • 排查系统问题
  • 自动化系统管理任务
  • 管理进程和服务
  • 配置系统资源

工作流阶段

阶段 1:环境评估
要调用的技能
  • bash-linux - Linux bash 模式
  • bash-pro - 专业 bash 脚本编写
  • bash-defensive-patterns - 防御性脚本编写
操作
  1. 确定操作系统和版本
  2. 检查可用工具和命令
  3. 验证权限和访问
  4. 评估系统资源
  5. 查看日志和错误消息
诊断命令
# System information
uname -a
cat /etc/os-release
hostnamectl

# Resource usage
top
htop
df -h
free -m

# Process information
ps aux
pgrep -f pattern
lsof -i :port

# Network status
netstat -tulpn
ss -tulpn
ip addr show
可复制粘贴的提示词
Use @bash-linux to diagnose system performance issues
阶段 2:脚本分析
要调用的技能
  • bash-defensive-patterns - 防御性脚本编写
  • shellcheck-configuration - ShellCheck lint 检查
  • bats-testing-patterns - Bats 测试
操作
  1. 运行 ShellCheck 进行 lint 检查
  2. 分析脚本结构
  3. 识别潜在问题
  4. 检查错误处理
  5. 验证变量使用
ShellCheck 用法
# Install ShellCheck
sudo apt install shellcheck  # Debian/Ubuntu
brew install shellcheck      # macOS

# Run ShellCheck
shellcheck script.sh
shellcheck -f gcc script.sh

# Fix common issues
# - Use quotes around variables
# - Check exit codes
# - Handle errors properly
可复制粘贴的提示词
Use @shellcheck-configuration to lint and fix shell scripts
阶段 3:调试
要调用的技能
  • systematic-debugging - 系统化调试
  • debugger - 调试专家
  • error-detective - 错误模式检测
操作
  1. 启用调试模式
  2. 添加日志语句
  3. 跟踪执行流
  4. 隔离失败的部分
  5. 单独测试各个组件
调试技巧
# Enable debug mode
set -x  # Print commands
set -e  # Exit on error
set -u  # Exit on undefined variable
set -o pipefail  # Pipeline failure detection

# Add logging
log() {
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >> /var/log/script.log
}

# Trap errors
trap 'echo "Error on line $LINENO"' ERR

# Test sections
bash -n script.sh  # Syntax check
bash -x script.sh  # Trace execution
可复制粘贴的提示词
Use @systematic-debugging to trace and fix shell script errors
阶段 4:脚本开发
要调用的技能
  • bash-pro - 专业脚本编写
  • bash-defensive-patterns - 防御性模式
  • linux-shell-scripting - Shell 脚本编写
操作
  1. 设计脚本结构
  2. 实现函数
  3. 添加错误处理
  4. 包含输入验证
  5. 添加帮助文档
脚本模板
#!/usr/bin/env bash
set -euo pipefail

# Constants
readonly SCRIPT_NAME=$(basename "$0")
readonly SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)

# Logging
log() {
    local level="$1"
    shift
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $*" >&2
}

info() { log "INFO" "$@"; }
warn() { log "WARN" "$@"; }
error() { log "ERROR" "$@"; exit 1; }

# Usage
usage() {
    cat <<EOF
Usage: $SCRIPT_NAME [OPTIONS]

Options:
    -h, --help      Show this help message
    -v, --verbose   Enable verbose output
    -d, --debug     Enable debug mode

Examples:
    $SCRIPT_NAME --verbose
    $SCRIPT_NAME -d
EOF
}

# Main function
main() {
    local verbose=false
    local debug=false

    while [[ $# -gt 0 ]]; do
        case "$1" in
            -h|--help)
                usage
                exit 0
                ;;
            -v|--verbose)
                verbose=true
                shift
                ;;
            -d|--debug)
                debug=true
                set -x
                shift
                ;;
            *)
                error "Unknown option: $1"
                ;;
        esac
    done

    info "Script started"
    # Your code here
    info "Script completed"
}

main "$@"
可复制粘贴的提示词
Use @bash-pro to create a production-ready backup script
Use @linux-shell-scripting to automate system maintenance tasks
阶段 5:测试
要调用的技能
  • bats-testing-patterns - Bats 测试框架
  • test-automator - 测试自动化
操作
  1. 编写 Bats 测试
  2. 测试边界情况
  3. 测试错误条件
  4. 验证预期输出
  5. 运行测试套件
Bats 测试示例
#!/usr/bin/env bats

@test "script returns success" {
    run ./script.sh
    [ "$status" -eq 0 ]
}

@test "script handles missing arguments" {
    run ./script.sh
    [ "$status" -ne 0 ]
    [ "$output" == *"Usage:"* ]
}

@test "script creates expected output" {
    run ./script.sh --output test.txt
    [ -f "test.txt" ]
}
可复制粘贴的提示词
Use @bats-testing-patterns to write tests for shell scripts
阶段 6:系统疑难排查
要调用的技能
  • devops-troubleshooter - DevOps 疑难排查
  • incident-responder - 事件响应
  • server-management - 服务器管理
操作
  1. 识别症状
  2. 检查系统日志
  3. 分析资源使用情况
  4. 测试连接性
  5. 验证配置
  6. 实施修复
疑难排查命令
# Check logs
journalctl -xe
tail -f /var/log/syslog
dmesg | tail

# Network troubleshooting
ping host
traceroute host
curl -v http://host
dig domain
nslookup domain

# Process troubleshooting
strace -p PID
lsof -p PID
iotop

# Disk troubleshooting
du -sh /*
find / -type f -size +100M
lsof | grep deleted
可复制粘贴的提示词
Use @devops-troubleshooter to diagnose server connectivity issues
Use @incident-responder to investigate system outage
阶段 7:自动化
要调用的技能
  • workflow-automation - 工作流自动化
  • cicd-automation-workflow-automate - CI/CD 自动化
  • linux-shell-scripting - Shell 脚本编写
操作
  1. 识别自动化机会
  2. 设计自动化工作流
  3. 实现脚本
  4. 使用 cron/systemd 调度
  5. 监控自动化运行状况
Cron 示例
# Edit crontab
crontab -e

# Backup every day at 2 AM
0 2 * * * /path/to/backup.sh

# Clean logs weekly
0 3 * * 0 /path/to/cleanup.sh

# Monitor disk space hourly
0 * * * * /path/to/monitor.sh
Systemd Timer 示例
# /etc/systemd/system/backup.timer
[Unit]
Description=Daily backup timer

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target
可复制粘贴的提示词
Use @workflow-automation to create automated system maintenance workflow

常见疑难排查场景

CPU 使用率过高
top -bn1 | head -20
ps aux --sort=-%cpu | head -10
pidstat 1 5
内存问题
free -h
vmstat 1 10
cat /proc/meminfo
磁盘空间
df -h
du -sh /* 2>/dev/null | sort -h
find / -type f -size +500M 2>/dev/null
网络问题
ip addr show
ip route show
ss -tulpn
curl -v http://target
服务故障
systemctl status service-name
journalctl -u service-name -f
systemctl restart service-name

质量门禁

在完成工作流之前,请验证:

  • 所有脚本均通过 ShellCheck
  • 测试通过 Bats
  • 已实现错误处理
  • 已配置日志记录
  • 文档完整
  • 已安排自动化

相关工作流捆绑包

  • development — 软件开发
  • cloud-devops — 云与 DevOps
  • security-audit — 安全测试
  • database — 数据库操作

限制

  • 仅当任务明确符合上述范围时,才使用此技能。
  • 请勿将输出视为特定环境验证、测试或专家评审的替代品。
  • 如果缺少必需的输入、权限、安全边界或成功标准,请停止并请求澄清。

评论

支持 Markdown