Generate robust bash scripts with error handling, logging, and best practices.
## ROLE
You are a DevOps engineer who writes production-grade shell scripts.
## CONTEXT
I need a bash script for:
**Script Requirements:**
- Purpose: [SCRIPT_PURPOSE]
- Input Parameters: [PARAMETERS]
- Operations: [OPERATIONS]
- Error Handling: [ERROR_HANDLING]
- Logging: [LOGGING_NEEDS]
- Platform: [PLATFORM]
## TASK
Generate production-ready bash script:
### 1. SCRIPT HEADER
```bash
#!/bin/bash
# [SCRIPT_NAME]
# Description: [PURPOSE]
# Usage: ./[script].sh [args]
# Author: [AUTHOR]
# Date: [DATE]
set -euo pipefail
IFS=$'\n\t'
```
### 2. CONFIGURATION
```bash
# Configuration variables
[CONFIG_VARIABLES]
```
### 3. HELPER FUNCTIONS
```bash
# Logging
log_info() { echo "[INFO] $(date '+%Y-%m-%d %H:%M:%S') - $*"; }
log_error() { echo "[ERROR] $(date '+%Y-%m-%d %H:%M:%S') - $*" >&2; }
log_debug() { [[ "${DEBUG:-}" == "true" ]] && echo "[DEBUG] $*"; }
# Cleanup
cleanup() {
# Cleanup code here
log_info "Cleanup completed"
}
trap cleanup EXIT
# Error handler
error_exit() {
log_error "$1"
exit "${2:-1}"
}
```
### 4. ARGUMENT PARSING
```bash
# Parse command line arguments
[ARGUMENT_PARSING_CODE]
```
### 5. VALIDATION
```bash
# Validate inputs and prerequisites
[VALIDATION_CODE]
```
### 6. MAIN LOGIC
```bash
main() {
log_info "Starting [SCRIPT_PURPOSE]"
[MAIN_LOGIC]
log_info "Completed successfully"
}
main "$@"
```
### 7. COMPLETE SCRIPT
```bash
[COMPLETE_SCRIPT]
```
### 8. USAGE EXAMPLES
```bash
# Basic usage
./[script].sh [args]
# With options
./[script].sh --option value
# Debug mode
DEBUG=true ./[script].sh
```
## RULES
- Use set -euo pipefail
- Quote all variables
- Handle errors gracefully
- Add helpful messages
- Make idempotent if possible
- Use functions for modularityOr press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
{ echo "[INFO] $(date '+%Y-%m-%d %H:%M:%S') - $*"; }{ echo "[ERROR] $(date '+%Y-%m-%d %H:%M:%S') - $*" >&2; }[ [[ "${DEBUG:-]{
# Cleanup code here
log_info "Cleanup completed"
}{
log_error "$1"
exit "${2:-1}{
log_info "Starting [SCRIPT_PURPOSE]"
[MAIN_LOGIC]
log_info "Completed successfully"
}[SCRIPT_PURPOSE][PARAMETERS][OPERATIONS][ERROR_HANDLING][LOGGING_NEEDS][PLATFORM][SCRIPT_NAME][PURPOSE][AUTHOR][DATE][CONFIG_VARIABLES][INFO][ERROR][DEBUG][ARGUMENT_PARSING_CODE][VALIDATION_CODE][MAIN_LOGIC][COMPLETE_SCRIPT]