Skill: bytesagain3/sysadmin-handbook (version 1.0.0)

--- version: "1.0.0" name: The Book Of Secret Knowledge description: "A collection of inspiring lists, manuals, cheatsheets, blogs, hacks, one-liners, cli/web tools and m the book of secret knowledge, python, awesome." --- # Sysadmin Handbook Sysadmin Handbook v2.0.0 — a thorough sysops toolkit for system administrators. Record, track, and manage all aspects of system administration from the command line. Every action is timestamped and logged locally for full auditability. ## Why Sysadmin Handbook? - Works entirely offline — your data never leaves your machine - Simple command-line interface, no GUI needed - Timestamped logging for every operation - Export to JSON, CSV, or plain text anytime - Automatic history and activity tracking - Searchable records across all operation types ## Getting Started ```bash # See all available commands sysadmin-handbook help # Check current health status sysadmin-handbook status # View summary statistics sysadmin-handbook stats ``` ## Commands ### Operations Commands Each command works in two modes: run without arguments to view recent entries, or pass input to record a new entry. | Command | Description | |---------|-------------| | `sysadmin-handbook scan <input>` | Record a scan operation (port scans, vulnerability scans, network sweeps) | | `sysadmin-handbook monitor <input>` | Log monitoring observations (service health, uptime checks, resource usage) | | `sysadmin-handbook report <input>` | Create report entries (incident reports, audit summaries, status updates) | | `sysadmin-handbook alert <input>` | Record alert events (threshold breaches, security warnings, service failures) | | `sysadmin-handbook top <input>` | Log top-level metrics (CPU hogs, memory consumers, disk leaders) | | `sysadmin-handbook usage <input>` | Track usage data (disk usage, bandwidth, API calls, license counts) | | `sysadmin-handbook check <input>` | Record health checks (service checks, config validation, dependency tests) | | `sysadmin-handbook fix <input>` | Document fixes applied (patches, config changes, workarounds) | | `sysadmin-handbook cleanup <input>` | Log cleanup operations (temp files, old logs, orphaned processes) | | `sysadmin-handbook backup <input>` | Track backup operations (full backups, incrementals, snapshots) | | `sysadmin-handbook restore <input>` | Record restore operations (data recovery, config rollbacks) | | `sysadmin-handbook log <input>` | General-purpose log entries (freeform notes, observations) | | `sysadmin-handbook benchmark <input>` | Record benchmark results (performance tests, load tests, I/O benchmarks) | | `sysadmin-handbook compare <input>` | Log comparison data (before/after, environment diffs, config comparisons) | ### Utility Commands | Command | Description | |---------|-------------| | `sysadmin-handbook stats` | Show summary statistics across all log categories | | `sysadmin-handbook export <fmt>` | Export all data (formats: `json`, `csv`, `txt`) | | `sysadmin-handbook search <term>` | Search across all entries for a keyword | | `sysadmin-handbook recent` | Show the 20 most recent history entries | | `sysadmin-handbook status` | Health check — version, data dir, entry count, disk usage | | `sysadmin-handbook help` | Show the built-in help message | | `sysadmin-handbook version` | Print version (v2.0.0) | ## Data Storage All data is stored locally in `~/.local/share/sysadmin-handbook/`. Structure: - **`scan.log`**, **`monitor.log`**, **`report.log`**, etc. — one log file per command, pipe-delimited (`timestamp|value`) - **`history.log`** — unified activity log across all commands - **`export.json`** / **`export.csv`** / **`export.txt`** — generated export files Each entry is stored as `YYYY-MM-DD HH:MM|<input>`. Use `export` to back up your data anytime. ## Requirements - Bash 4+ (uses `set -euo pipefail`) - Standard Unix utilities (`date`, `wc`, `du`, `tail`, `grep`, `sed`, `cat`) - No external dependencies or internet access needed ## When to Use 1. **Incident response tracking** — Log scan results, alerts, and fixes during an active incident so you have a complete timeline for the post-mortem 2. **Daily ops journaling** — Record monitoring observations, health checks, and cleanup tasks as you go through your sysadmin routine 3. **Backup & restore auditing** — Track every backup and restore operation with timestamps to prove compliance or diagnose failures 4. **Performance benchmarking** — Store benchmark results over time and use `compare` to track regressions or improvements across deploys 5. **Team handoff documentation** — Log everything during your shift so the next admin can run `recent` or `search` to get up to speed instantly ## Examples ```bash # Record a network scan result sysadmin-handbook scan "192.168.1.0/24 — 14 hosts up, 3 with open SSH" # Log a monitoring observation sysadmin-handbook monitor "web-prod-01 CPU at 92% for 15 minutes" # Document a fix you applied sysadmin-handbook fix "Increased nginx worker_connections from 1024 to 4096" # Track a backup operation sysadmin-handbook backup "Full backup of /data completed — 48GB, 23 min" # Export everything to JSON for archival sysadmin-handbook export json # Search all logs for a keyword sysadmin-handbook search "nginx" # View recent activity across all commands sysadmin-handbook recent ``` ## Output All commands output to stdout. Redirect to a file if needed: ```bash sysadmin-handbook stats > report.txt sysadmin-handbook export csv ``` ## Configuration Set `SYSADMIN_HANDBOOK_DIR` environment variable to override the default data directory (`~/.local/share/sysadmin-handbook/`). --- Powered by BytesAgain | bytesagain.com | [REDACTED_SECRET]

path: scripts/script.sh
content: #!/usr/bin/env bash
# Sysadmin Handbook — sysops tool
# Powered by BytesAgain | bytesagain.com | [REDACTED_SECRET]
set -euo pipefail

DATA_DIR="${HOME}/.local/share/sysadmin-handbook"
mkdir -p "$DATA_DIR"

_log() { echo "$(date '+%m-%d %H:%M') $1: $2" >> "$DATA_DIR/history.log"; }
_version() { echo "sysadmin-handbook v2.0.0"; }

_help() {
    echo "Sysadmin Handbook v2.0.0 — sysops toolkit"
    echo ""
    echo "Usage: sysadmin-handbook <command> [args]"
    echo ""
    echo "Commands:"
    echo "  scan               Scan"
    echo "  monitor            Monitor"
    echo "  report             Report"
    echo "  alert              Alert"
    echo "  top                Top"
    echo "  usage              Usage"
    echo "  check              Check"
    echo "  fix                Fix"
    echo "  cleanup            Cleanup"
    echo "  backup             Backup"
    echo "  restore            Restore"
    echo "  log                Log"
    echo "  benchmark          Benchmark"
    echo "  compare            Compare"
    echo "  stats              Summary statistics"
    echo "  export <fmt>       Export (json|csv|txt)"
    echo "  search <term>      Search entries"
    echo "  recent             Recent activity"
    echo "  status             Health check"
    echo "  help               Show this help"
    echo "  version            Show version"
    echo ""
    echo "Data: $DATA_DIR"
}

_stats() {
    echo "=== Sysadmin Handbook Stats ==="
    local total=0
    for f in "$DATA_DIR"/*.log; do
        [ -f "$f" ] || continue
        local name=$(basename "$f" .log)
        local c=$(wc -l < "$f")
        total=$((total + c))
        echo "  $name: $c entries"
    done
    echo "  ---"
    echo "  Total: $total entries"
    echo "  Data size: $(du -sh "$DATA_DIR" 2>/dev/null | cut -f1)"
}

_export() {
    local fmt="${1:-json}"
    local out="$DATA_DIR/export.$fmt"
    case "$fmt" in
        json)
            echo "[" > "$out"
            local first=1
            for f in "$DATA_DIR"/*.log; do
                [ -f "$f" ] || continue
                local name=$(basename "$f" .log)
                while IFS='|' read -r ts val; do
                    [ $first -eq 1 ] && first=0 || echo "," >> "$out"
                    printf '  {"type":"%s","time":"%s","value":"%s"}' "$name" "$ts" "$val" >> "$out"
                done < "$f"
            done
            echo "\n]" >> "$out"
            ;;
        csv)
            echo "type,time,value" > "$out"
            for f in "$DATA_DIR"/*.log; do
                [ -f "$f" ] || continue
                local name=$(basename "$f" .log)
                while IFS='|' read -r ts val; do echo "$name,$ts,$val" >> "$out"; done < "$f"
            done
            ;;
        txt)
            echo "=== Sysadmin Handbook Export ===" > "$out"
            for f in "$DATA_DIR"/*.log; do
                [ -f "$f" ] || continue
                echo "--- $(basename "$f" .log) ---" >> "$out"
                cat "$f" >> "$out"
            done
            ;;
        *) echo "Formats: json, csv, txt"; return 1 ;;
    esac
    echo "Exported to $out ($(wc -c < "$out") bytes)"
}

_status() {
    echo "=== Sysadmin Handbook Status ==="
    echo "  Version: v2.0.0"
    echo "  Data dir: $DATA_DIR"
    echo "  Entries: $(cat "$DATA_DIR"/*.log 2>/dev/null | wc -l) total"
    echo "  Disk: $(du -sh "$DATA_DIR" 2>/dev/null | cut -f1)"
    echo "  Last: $(tail -1 "$DATA_DIR/history.log" 2>/dev/null || echo never)"
    echo "  Status: OK"
}

_search() {
    local term="${1:?Usage: sysadmin-handbook search <term>}"
    echo "Searching for: $term"
    for f in "$DATA_DIR"/*.log; do
        [ -f "$f" ] || continue
        local m=$(grep -i "$term" "$f" 2>/dev/null || true)
        if [ -n "$m" ]; then
            echo "  --- $(basename "$f" .log) ---"
            echo "$m" | sed 's/^/    /'
        fi
    done
}

_recent() {
    echo "=== Recent Activity ==="
    tail -20 "$DATA_DIR/history.log" 2>/dev/null | sed 's/^/  /' || echo "  No activity yet."
}

case "${1:-help}" in
    scan)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent scan entries:"
            tail -20 "$DATA_DIR/scan.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook scan <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/scan.log"
            local total=$(wc -l < "$DATA_DIR/scan.log")
            echo "  [Sysadmin Handbook] scan: $input"
            echo "  Saved. Total scan entries: $total"
            _log "scan" "$input"
        fi
        ;;
    monitor)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent monitor entries:"
            tail -20 "$DATA_DIR/monitor.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook monitor <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/monitor.log"
            local total=$(wc -l < "$DATA_DIR/monitor.log")
            echo "  [Sysadmin Handbook] monitor: $input"
            echo "  Saved. Total monitor entries: $total"
            _log "monitor" "$input"
        fi
        ;;
    report)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent report entries:"
            tail -20 "$DATA_DIR/report.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook report <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/report.log"
            local total=$(wc -l < "$DATA_DIR/report.log")
            echo "  [Sysadmin Handbook] report: $input"
            echo "  Saved. Total report entries: $total"
            _log "report" "$input"
        fi
        ;;
    alert)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent alert entries:"
            tail -20 "$DATA_DIR/alert.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook alert <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/alert.log"
            local total=$(wc -l < "$DATA_DIR/alert.log")
            echo "  [Sysadmin Handbook] alert: $input"
            echo "  Saved. Total alert entries: $total"
            _log "alert" "$input"
        fi
        ;;
    top)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent top entries:"
            tail -20 "$DATA_DIR/top.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook top <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/top.log"
            local total=$(wc -l < "$DATA_DIR/top.log")
            echo "  [Sysadmin Handbook] top: $input"
            echo "  Saved. Total top entries: $total"
            _log "top" "$input"
        fi
        ;;
    usage)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent usage entries:"
            tail -20 "$DATA_DIR/usage.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook usage <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/usage.log"
            local total=$(wc -l < "$DATA_DIR/usage.log")
            echo "  [Sysadmin Handbook] usage: $input"
            echo "  Saved. Total usage entries: $total"
            _log "usage" "$input"
        fi
        ;;
    check)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent check entries:"
            tail -20 "$DATA_DIR/check.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook check <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/check.log"
            local total=$(wc -l < "$DATA_DIR/check.log")
            echo "  [Sysadmin Handbook] check: $input"
            echo "  Saved. Total check entries: $total"
            _log "check" "$input"
        fi
        ;;
    fix)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent fix entries:"
            tail -20 "$DATA_DIR/fix.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook fix <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/fix.log"
            local total=$(wc -l < "$DATA_DIR/fix.log")
            echo "  [Sysadmin Handbook] fix: $input"
            echo "  Saved. Total fix entries: $total"
            _log "fix" "$input"
        fi
        ;;
    cleanup)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent cleanup entries:"
            tail -20 "$DATA_DIR/cleanup.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook cleanup <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/cleanup.log"
            local total=$(wc -l < "$DATA_DIR/cleanup.log")
            echo "  [Sysadmin Handbook] cleanup: $input"
            echo "  Saved. Total cleanup entries: $total"
            _log "cleanup" "$input"
        fi
        ;;
    backup)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent backup entries:"
            tail -20 "$DATA_DIR/backup.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook backup <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/backup.log"
            local total=$(wc -l < "$DATA_DIR/backup.log")
            echo "  [Sysadmin Handbook] backup: $input"
            echo "  Saved. Total backup entries: $total"
            _log "backup" "$input"
        fi
        ;;
    restore)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent restore entries:"
            tail -20 "$DATA_DIR/restore.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook restore <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/restore.log"
            local total=$(wc -l < "$DATA_DIR/restore.log")
            echo "  [Sysadmin Handbook] restore: $input"
            echo "  Saved. Total restore entries: $total"
            _log "restore" "$input"
        fi
        ;;
    log)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent log entries:"
            tail -20 "$DATA_DIR/log.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook log <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/log.log"
            local total=$(wc -l < "$DATA_DIR/log.log")
            echo "  [Sysadmin Handbook] log: $input"
            echo "  Saved. Total log entries: $total"
            _log "log" "$input"
        fi
        ;;
    benchmark)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent benchmark entries:"
            tail -20 "$DATA_DIR/benchmark.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook benchmark <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/benchmark.log"
            local total=$(wc -l < "$DATA_DIR/benchmark.log")
            echo "  [Sysadmin Handbook] benchmark: $input"
            echo "  Saved. Total benchmark entries: $total"
            _log "benchmark" "$input"
        fi
        ;;
    compare)
        shift
        if [ $# -eq 0 ]; then
            echo "Recent compare entries:"
            tail -20 "$DATA_DIR/compare.log" 2>/dev/null || echo "  No entries yet. Use: sysadmin-handbook compare <input>"
        else
            local input="$*"
            local ts=$(date '+%Y-%m-%d %H:%M')
            echo "$ts|$input" >> "$DATA_DIR/compare.log"
            local total=$(wc -l < "$DATA_DIR/compare.log")
            echo "  [Sysadmin Handbook] compare: $input"
            echo "  Saved. Total compare entries: $total"
            _log "compare" "$input"
        fi
        ;;
    stats) _stats ;;
    export) shift; _export "$@" ;;
    search) shift; _search "$@" ;;
    recent) _recent ;;
    status) _status ;;
    help|--help|-h) _help ;;
    version|--version|-v) _version ;;
    *)
        echo "Unknown: $1 — run 'sysadmin-handbook help'"
        exit 1
        ;;
esac

Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (CRITICAL)