
Monitorear el uso del disco y alertar si supera el 80%.
#!/bin/bash usage=$(df / | awk 'NR==2 {print $5}' | sed 's/%//') [ "$usage" -gt 80 ] && echo "Disk usage is above 80%! ($usage%)"Limpiar directorio /tmp con más de 7 días de antigüedad
#!/bin/bash find /tmp -type f -mtime +7 -exec rm -f {} \;
Monitorizar el servicio web y alertar en caso de fallo
#!/bin/bash find /tmp -type f -mtime +7 -exec rm -f {} \;
Rotar registros y conservar los últimos 5
#!/bin/bash cd /var/log/myapp ls -tp | grep -v '/$' | tail -n +6 | xargs -I {} rm -- {}
Copia de seguridad diaria de la base de datos MySQL con Timestamps
#!/bin/bash mysqldump -u root -pYourPassword dbname > /backup/db_$(date +%F).sql
Validar una dirección IP en un archivo de texto
#!/bin/bash grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' ips.txt | while read ip; do if [[ $ip =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then echo "Valid: $ip"; fi done
Hacer ping a servidores desde un archivo
#!/bin/bash while read ip; do ping -c 1 $ip > /dev/null && echo "$ip is up" || echo "$ip is down" done < servers.txt
Enviar por Email los procesos que más consumen CPU
#!/bin/bash ps -eo pid,comm,%cpu --sort=-%cpu | head -n 6 | mail -s "Top CPU processes" your@email.com
Conectarse por SSH a varios servidores y ejecutar comandos
#!/bin/bash while read server; do ssh user@$server 'uptime' done < servers.txt
Archivar registros de aplicaciones en AWS S3
#!/bin/bash tar czf app_logs_$(date +%F).tar.gz /var/log/myapp/ aws s3 cp app_logs_$(date +%F).tar.gz s3://nombre_del_bucket/
Reiniciar el servicio si está inactivo
#!/bin/bash if ! systemctl is-active --quiet nginx; then systemctl restart nginx fi
Monitorear la expiración del certificado SSL
#!/bin/bash echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -enddate
Contar inicios de sesión fallidos en el archivo de registro
#!/bin/bash grep "Failed password" /var/log/auth.log | wc -l
Informar usuarios con UID mayor a 1000
#!/bin/bash awk -F: '$3 > 1000 {print $1, $3}' /etc/passwd
Encuentra y elimina procesos zombi
#!/bin/bash ps aux | awk '$8=="Z" {print $2}' | xargs -r kill -9
Comparar dos directorios
#!/bin/bash diff -r dir1/ dir2/
Monitorear el ancho de banda de la red en tiempo real
#!/bin/bash iftop
Crear usuarios desde un archivo CSV
#!/bin/bash while IFS=, read -r user pass; do useradd -m $user && echo "$user:$pass" | chpasswd done < users.csv
Alerta si el contenedor Docker no se está ejecutando
#!/bin/bash ! docker ps | grep -q mycontainer && echo "Container is not running!"
Implementar automáticamente un sitio estático mediante rsync
#!/bin/bash rsync -avz /path/to/site/ user@server:/var/www/html/
Git Pull y Reiniciar servicio
#!/bin/bash cd /opt/myapp && git pull && systemctl restart myapp
Generar inventario dinámico de Ansible
#!/bin/bash cat <<EOF { "all": { "hosts": ["192.168.1.10", "192.168.1.11"] } } EOF
Validar archivos YAML y JSON
#!/bin/bash yamllint file.yaml jq empty file.json