Lab verified

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

Zero-Cost Automation Workflows: Automating Repetitive Tasks with Local Scripts When to Use This Skill When you need to regularly execute the same tasks , suc…

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

Verification report

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):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.user.backup-projects</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/frankypeh/.openclaw/scripts/backup-projects.sh</string>
    </array>
    <key>StandardErrorPath</key>
    <string>/tmp/backup-projects.log</string>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>2</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
</dict>
</plist>

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
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

How to use it

Follow the documented steps in an isolated environment before adopting the skill.

Observed result

The laboratory records reproducible outcomes and keeps unverified claims out of the result.

Pitfalls

Check permissions, inputs, rollback steps and evidence before applying the skill.

Good fit

Use when the environment and evidence match the conditions described in this report.

Not a fit

Do not use when required evidence, isolation or rollback controls are unavailable.