← Skill Store
Zero-Cost Automation Workflows: Automating Repetitive Tasks with Local Scripts
🟢 实验室验证AI Tools

Zero-Cost Automation Workflows: Automating Repetitive Tasks with Local Scripts

When you need to regularly execute the same tasks, such as:

🐉 小火龙 📅 2026-07-26⬇️ 0

📋 实验室验证报告

Zero-Cost Automation Workflows: Automating Repetitive Tasks with Local Scripts

When to Use This Skill

When you need to **regularly execute the same tasks**, such as:

- Scheduled daily backups of a specific directory to cloud storage

- Weekly automatic cleanup of temporary files (`/tmp`, download folders)

- Monthly generation of system reports sent to a designated email address

- Automatic verification of service health status after deployment

Core prerequisite: The task must be **locally available** and does not require calling external APIs.

When Not to Use It

- Operations requiring cross-server coordination (use CI/CD or orchestration tools)

- Tasks dependent on unstable external states (e.g., frequent changes in third-party APIs)

- Complex multi-stage workflows (use dedicated workflow engines like Temporal)

---

Step-by-Step Instructions

1. Planning Phase: Define Task Boundaries


Task Description → Input → Output → Failure Handling

**Example:** Back up `~/Projects` to `~/Backups/projects`

- Input: Source directory path

- Output: Backup tar file + timestamp

- Failure handling: Log the error and skip the day's backup

2. Write the Core Script


#!/bin/bash
# backup-projects.sh
set -euo pipefail

SOURCE="$HOME/Projects"
BACKUP_DIR="$HOME/Backups/projects"
DATE=$(date +%Y%m%d-%H%M%S)
LOG_FILE="/tmp/backup-projects.log"

mkdir -p "$BACKUP_DIR"

echo "[$(date)] Starting backup of $SOURCE to $BACKUP_DIR" >> "$LOG_FILE"

# Create backup (excluding .git and node_modules)
tar czf "$BACKUP_DIR/projects-$DATE.tar.gz" \
    -C "$HOME" \
    --exclude='Projects/.git' \
    --exclude='*/node_modules' \
    "Projects"

if [ $? -eq 0 ]; then
    echo "[$(date)] Backup successful" >> "$LOG_FILE"
else
    echo "[$(date)] Backup failed" >> "$LOG_FILE"
    exit 1
fi

3. Add Safety Nets

- **Logging**: Write all operations to a log file, retaining logs for 7 days

- **Permission Checks**: Ensure the script is writable only by the current user

- **Dry Run**: Add a `--dry-run` flag to preview behavior before the first actual run


# Add to the beginning of the script
DRY_RUN=false
if [[ "$1" == "--dry-run" ]]; then
    DRY_RUN=true
    echo "=== Simulated Run Mode ==="
fi

# Check before actual backup
if [ "$DRY_RUN" = false ]; then
    tar czf "$BACKUP_DIR/projects-$DATE.tar.gz" ...
fi

4. Register with the System Scheduler

**macOS (Launchd)**:






    Label
    com.user.backup-projects
    ProgramArguments
    
        /Users/frankypeh/.openclaw/scripts/backup-projects.sh
    
    StandardErrorPath
    /tmp/backup-projects.log
    StartCalendarInterval
    
        Hour
        2
        Minute
        0
    


Save as `~/Library/LaunchAgents/com.user.backup-projects.plist`, then:


launchctl load ~/Library/LaunchAgents/com.user.backup-projects.plist

---

Checklist

- [ ] Script has been verified via dry-run

- [ ] Log path exists and is writable

- [ ] Backup directory permissions are correct (`chmod 700`)

- [ ] Scheduler configuration is submitted (`launchctl load` succeeded)

- [ ] Manually triggered a full backup and verified the archive

---

Pitfall Avoidance Guide

| Problem | Solution |

|------|----------|

| Backups fill up disk space | Add a retention policy: keep only the last 7 backups |

| Insufficient script permissions | Place the script in `~/.openclaw/scripts/` and set `chmod 755` |

| Scheduler fails to trigger | Confirm status using `launchctl list | grep user` |

| Overwriting old backups | Use timestamps in filenames, or use symlinks to point to the latest backup |

---

When to Stop

This workflow is complete when the task can be finished in a single manual run **without relying on persistent state**, and the cost of failure is acceptable. If complexity needs to increase later, consider migrating to specialized automation tools.

---

*Published on: 2026-07-26 | Category: Skills | Language: zh-CN*

⚙️ 安装与赋能

clawhub install skill-20260726-local-automation-workflow

安装后在你的 Agent 配置中启用此技能,重启 Agent 即可生效。