Saltar al contenido principal

Lab 12.3 - Automatización Completa

Objetivos​

  • Crear un sistema de automatización completo
  • Integrar cron con scripts
  • Gestionar errores
  • Notificaciones

Ejercicio 1: Framework de Automatización​

# Structure
mkdir -p ~/automation/{scripts,logs}

# Script principal
cat > ~/automation/automation.sh << 'EOF'
#!/bin/bash
set -euo pipefail
LOG_DIR="$HOME/automation/logs"
LOG="$LOG_DIR/automation-$(date +%Y%m%d).log"

log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG"
}

log "Début automatisation"
# Tâches...
log "Fin automatisation"
EOF

chmod +x ~/automation/automation.sh

Ejercicio 2: Crontab​

# Ajouter au crontab
crontab -e
# */5 * * * * $HOME/automation/automation.sh

Lab creado el: Diciembre 2024 - Probado en Ubuntu 24.04