Automation
Scripting, scheduling, and configuration management.
Topics
| Topic | Description |
|---|---|
Bash Scripting |
Best practices, error handling, common patterns |
systemd Timers |
Scheduled tasks, calendar expressions |
Ansible |
Playbooks, roles, inventory, idempotency |
systemd Timers
systemd timers replace cron with better logging and dependency management.
Bash Best Practices
#!/usr/bin/env bash
set -euo pipefail
# Fail on:
# -e: any command error
# -u: undefined variables
# -o pipefail: pipe failures
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly LOG_FILE="/var/log/script.log"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
}
main() {
log "Starting..."
# Your code here
log "Complete"
}
main "$@"