انتقل إلى المحتوى الرئيسي

المختبر 12.3 - الأتمتة الكاملة

الأهداف​

  • إنشاء نظام أتمتة كامل
  • دمج cron مع السكربتات
  • إدارة الأخطاء
  • الإشعارات

التمرين 1: إطار عمل الأتمتة​

# 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

التمرين 2: Crontab​

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

تم إنشاء المختبر في: ديسمبر 2024 - تم اختباره على Ubuntu 24.04