home / skills / openclaw / skills / automation

automation skill

/skills/sa9saq/automation

This skill automates repetitive tasks and optimizes workflows using OpenClaw cron, shell scripts, and system tools.

npx playbooks add skill openclaw/skills --skill automation

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
3.1 KB
---
name: automation
description: Task automation specialist. Workflow optimization and scheduled tasks.
---

# Task Automation

Automate repetitive tasks and optimize workflows using OpenClaw cron, shell scripts, and system tools.

## Instructions

1. **Identify the task**: Ask what the user wants automated — frequency, trigger, input/output.
2. **Choose the right tool**:

   | Task Type | Tool | Example |
   |-----------|------|---------|
   | Periodic checks | OpenClaw cron | Email check every 30 min |
   | File processing | Shell + cron | Compress logs nightly |
   | API polling | curl + jq + cron | Price alerts |
   | Web scraping | Puppeteer / fetch | Competitor monitoring |
   | Data pipeline | Shell pipeline | CSV → JSON → API |
   | Event-driven | Webhooks / inotifywait | File change triggers |

3. **Implement with OpenClaw cron** (preferred for agent tasks):
   ```bash
   # Example: System event every 30 minutes
   openclaw cron add --name "task-name" \
     --schedule "*/30 * * * *" \
     --payload '{"kind":"systemEvent","text":"Check X notifications"}'
   ```

4. **Implement with system cron** (for shell scripts):
   ```bash
   # Edit crontab
   crontab -e
   # Add entry: every day at 2 AM
   0 2 * * * /path/to/backup.sh >> /var/log/backup.log 2>&1
   ```

5. **Implement with systemd timers** (for services):
   ```ini
   # /etc/systemd/system/task.timer
   [Timer]
   OnCalendar=*-*-* 02:00:00
   Persistent=true
   [Install]
   WantedBy=timers.target
   ```

## Automation Patterns

### Retry with Backoff
```bash
#!/bin/bash
MAX_RETRIES=3
DELAY=5
for i in $(seq 1 $MAX_RETRIES); do
  if your_command; then break; fi
  echo "Retry $i/$MAX_RETRIES in ${DELAY}s..."
  sleep $DELAY
  DELAY=$((DELAY * 2))
done
```

### File Watcher
```bash
inotifywait -m -e modify,create /path/to/watch | while read dir action file; do
  echo "File $file was $action"
  # trigger processing
done
```

### Idempotent Scripts
```bash
# Use lock files to prevent concurrent runs
LOCKFILE="/tmp/mytask.lock"
if [ -f "$LOCKFILE" ]; then echo "Already running"; exit 0; fi
trap "rm -f $LOCKFILE" EXIT
touch "$LOCKFILE"
# ... your task here
```

### Pipeline with Error Handling
```bash
set -euo pipefail
fetch_data | transform_json | upload_result \
  || { echo "Pipeline failed at stage $?"; notify_admin; exit 1; }
```

## Cron Expression Reference

| Expression | Meaning |
|-----------|---------|
| `*/5 * * * *` | Every 5 minutes |
| `0 */2 * * *` | Every 2 hours |
| `0 9 * * 1-5` | Weekdays at 9 AM |
| `0 2 * * *` | Daily at 2 AM |
| `0 0 * * 0` | Weekly on Sunday midnight |
| `0 0 1 * *` | Monthly on the 1st |

## Security

- **Never store secrets in crontab** — use environment variables or secret files
- **Log all automated actions** — append to `~/.automation/logs/`
- **Rate limit API calls** — respect service terms
- **Use lock files** — prevent duplicate runs
- **Validate inputs** — never pass unsanitized data to shell commands

## Requirements

- `cron` or `systemd` (pre-installed on Linux)
- OpenClaw for agent-based automation
- Optional: `inotifywait` (inotify-tools), `jq`, `curl`

Overview

This skill is a task automation specialist that designs, schedules, and optimizes repetitive workflows using cron, systemd, shell tooling, and OpenClaw agent tasks. It focuses on reliable, idempotent automation with clear logging, error handling, and secure secret management. The goal is to reduce manual work and ensure predictable, auditable task execution.

How this skill works

I identify the task frequency, triggers, inputs, and expected outputs, then pick the right execution model: OpenClaw cron for agent-driven events, system cron for simple scheduled scripts, or systemd timers for service-managed schedules. Implementations use small, testable shell scripts or pipelines with retries, backoff, input validation, and lock files to avoid concurrency. All tasks include logging, rate limiting for external APIs, and secure handling of secrets via environment variables or protected files.

When to use it

  • Run periodic checks or agent-triggered notifications (e.g., every 30 minutes).
  • Process or rotate files nightly (log compression, backup pipelines).
  • Poll APIs or websites for updates and alerts (price/availability trackers).
  • Trigger jobs on file changes or system events (inotify/watchers).
  • Manage long-running services or scheduled maintenance with systemd timers.

Best practices

  • Keep scripts idempotent and use lock files to prevent concurrent runs.
  • Log actions to a central directory and rotate logs regularly.
  • Never store secrets in crontab; use environment variables or protected secret files.
  • Add retry with exponential backoff and fail-fast pipeline error handling.
  • Validate and sanitize all inputs before passing to shell commands.

Example use cases

  • Schedule daily backups at 2:00 AM using a cron job that calls a backup script and logs output.
  • Create an OpenClaw cron entry to check notifications every 30 minutes and post system events.
  • Use inotifywait to trigger processing when new files arrive in a watched directory.
  • Poll a REST API every 5 minutes with curl and jq, with rate limiting and alerts on failures.
  • Implement a systemd timer for a maintenance task that must run with service-level guarantees.

FAQ

When should I use OpenClaw cron vs system cron?

Use OpenClaw cron for agent-integrated tasks and event-driven agent workflows; use system cron for simple local shell scripts where agent context is not needed.

How do I prevent overlapping runs?

Use lock files or flock in scripts, and ensure scripts check for existing locks and exit safely if a lock exists.

What is the recommended error strategy for pipelines?

Use set -euo pipefail, propagate errors, notify on failures, and implement retries with exponential backoff for transient errors.