Advertisement
Sergio_Istea

dirmon.sh

Oct 26th, 2022
1,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.44 KB | None | 0 0
  1. #!/bin/bash
  2. # Guardamos en un array los directorios pasados como argumentos
  3. #arg=( $@ )
  4.  
  5. # Monitorizar un directorio y evaluar la cantidad de ficheros que contiene, si le llega a cierto numero eliminar los que tengan mas 15 dias.
  6.  
  7. dir=/etc
  8.  
  9. cant=10000
  10.  
  11.  
  12. while true;do
  13.  
  14.     files=$(find ./ -maxdepth 1 -type f -not -path '*/.*' | wc -l)
  15.  
  16.     if [ $files -lt 1000 ]; then
  17.         continue
  18.     fi
  19.  
  20.     find $dir -mtime +15 -type f -exec rm {} \;
  21.  
  22. done
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement