---
name: bash-script-automation-expert
description: "A robust, commented bash script for a recurring system or deployment task, with safe error handling, logging, and the exact tools you chose. Use when someone needs a bash script to automate a backup, deployment, or other repetitive system task on a specific OS. Do not use for scheduling expressions alone or full configuration management. Related topics: devops, coding, automation."
---

# Bash Script Automation Expert

A robust, commented bash script for a recurring system or deployment task, with safe error handling, logging, and the exact tools you chose.

## When to use

Use this skill when someone needs a bash script to automate a backup, deployment, or other repetitive system task on a specific OS. Do not use it for scheduling expressions alone or full configuration management.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Break the task into ordered operations and the failure modes of each.
3. Write the script with a header, variables at the top, and prerequisite checks for the chosen tools.
4. Add the requested logging, strict error handling, and colour, with a trap for cleanup.
5. Use only flags valid on the target OS, done when no GNU-only option appears in a macOS script.
6. Add run and scheduling instructions and a dry-run mode for any destructive step.

## Inputs

- **What the script should do** (longer free text)
- **Target OS** (choose one: Linux Debian or Ubuntu, macOS, CentOS or RHEL, Alpine)
- **Tools to use** (choose any: tar, rsync, curl, awk, sed, grep)
- **Log output to a file** (choose one: Yes, No)
- **Include strict error handling** (choose one: Yes, No)
- **Colour-coded terminal output** (choose one: Yes, No)

## Output

The complete commented script in one code block, then brief run, schedule, and dry-run instructions.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Bash Automation Script

Write a bash script for the task below.

- What the script should do: {{What the script should do}}
- Target OS: {{Target OS}}
- Tools to use: {{Tools to use}}
- Log output to a file: {{Log output to a file}}
- Include strict error handling: {{Include strict error handling}}
- Colour-coded terminal output: {{Colour-coded terminal output}}

Write the complete script with a shebang, a header comment explaining purpose and usage, and a comment on each non-obvious command. Quote every variable, check that required tools exist before starting, and use a trap to clean up temp files. With strict error handling on, use set -euo pipefail and explain what it changes. Make paths and thresholds variables at the top. Use only commands and flags that exist on the target OS, since macOS and Linux differ. End with how to run it, how to schedule it, and a safe dry-run option for anything that deletes.

## Pitfalls

- Using GNU flags such as sed -i without a suffix on macOS, where they behave differently.
- Leaving variables unquoted so paths with spaces break or delete the wrong thing.
- Deleting old files with no dry-run or path check, which can wipe the wrong directory.
