nand-storage-cleanup.py
Flash NAND memory management script by truncating large log files.
The 128 MB NAND flash memory is shared between the RouterOS system and user data. Logs can quickly saturate the space. This Bash script uses standard Linux commands (available via the RouterOS shell) to truncate .log files. It is crucial for outdoor installations where physical access for a reset is difficult.
nand-storage-cleanup.py
#!/bin/bash
# Nettoyage des logs pour préserver la NAND Flash (128 Mo)
# À exécuter quotidiennement via le scheduler
LOG_DIR="/log"
MAX_SIZE=1000000 # 1 MB max par fichier
for file in $LOG_DIR/*.log; do
if [ -f "$file" ]; then
SIZE=$(stat -c%s "$file")
if [ "$SIZE" -gt "$MAX_SIZE" ]; then
echo "Nettoyage de $file (taille: $SIZE)"
echo "" > "$file" # Tronque le fichier au lieu de le supprimer
fi
fi
done
# Vider les logs système RouterOS
/log print where topics="info,warning" | grep -v "current" | awk '{print $1}' | while read id; do
/log remove $id
done