Tecnologia

Bash scripting: 10 script pratici per automatizzare Linux

· · 👁 1 · ❤️ 0 · 💬 0

Il bash scripting e la skill piu utile per chi lavora con Linux. Con 20-30 righe automatizzi task che richiederebbero ore.

Basi

#!/bin/bash
NOME="Elfrid" && echo "Ciao $NOME"
if [ $ETA -gt 18 ]; then echo "Adulto"; fi
for i in {1..5}; do echo "Iter $i"; done

Script 1: Backup automatico

#!/bin/bash
SOURCE="/home/$USER/Documenti"
DEST="/backup"
DATE=$(date +%Y%m%d_%H%M%S)
tar -czf "$DEST/backup_$DATE.tar.gz" "$SOURCE"
find "$DEST" -name "backup_*.tar.gz" -mtime +30 -delete
echo "Backup: $DATE"

Script 2: Monitor risorse

#!/bin/bash
CPU=$(top -bn1 | grep "Cpu" | awk '{print int($2)}')
RAM=$(free | grep Mem | awk '{print int($3/$2*100)}')
echo "CPU: ${CPU}% | RAM: ${RAM}%"
[ $CPU -gt 80 ] && echo "ALERT CPU alta!"

Script 3: Deploy Docker

#!/bin/bash
cd /opt/myapp
docker compose pull
docker compose up -d --remove-orphans
docker image prune -f

Script 4: Password generator

#!/bin/bash
for i in $(seq 1 5); do
    tr -dc 'A-Za-z0-9!@#' < /dev/urandom | head -c 20; echo
done

Conclusione

Ogni task ripetitivo e candidato per uno script. Inizia semplice e aggiungi error handling gradualmente.

← Torna al Blog

📚 Articoli correlati

📝
Disco ottico o USB: perché nel 2026 non ha più senso usare i CD/DVD
Elfrid · 27/04/2026
📝
La licenza Windows sul tuo PC: cos'è, dove si trova e come usarla
Elfrid · 27/04/2026
📝
Come costruire un PC gaming nel 2026: guida completa componente per componente
Elfrid · 27/04/2026

💬 Commenti (0)

Nessun commento ancora. Sii il primo!

Accedi per lasciare un commento.