Script para remover arquivos com base no valor limite [duplicado]

1

Eu tenho um arquivo antigo no meu servidor Linux e preciso remover os arquivos com mais de 5 dias, com base no valor limite.

log_space_checker() {
        Use=$(df -kh /logs | awk 'END{gsub("%",""); print $4}');
        DATAUSE=$(df -kh /logs | awk 'END{gsub("%",""); print $4}');
}

remove_files(){
        RemoveFiles="/logs/abc/abc.log.*"
        find "$RemoveFiles" -mtime +1 -type f -delete
        }

disk_space_monitor() {
        log_space_checker;

        if [[ $DATAUSE -gt $TH ]] ; then
                remove_files;
        fi

}

TH=7

disk_space_monitor

O script está correto?

    
por shabaz 26.07.2016 / 08:06

1 resposta

1

Eu gostaria de algo assim

#!/bin/bash
#

########################################################################
#
log_space_checker() {
    local target="$1"                 # Log file template
    local directory="${target%/*}"    # Directory holding log files
    df -k "$directory" | awk 'NR>1 {print gensub("^.* ([1-9][0-9]*)%.*", "\1", 1)}'
}

########################################################################
#
remove_files(){
    local logfiles="$1"               # Log file template
    find $logfiles -mtime +1 -type f -print ## -delete
}

########################################################################
#
disk_space_monitor() {
    local threshold="$1"              # Threshold%
    local target="$2"                 # Log files to delete 
    local pct_used=$(log_space_checker "$2");

    if [[ $pct_used -gt $threshold ]]
    then
        remove_files "$2"
    fi
}

########################################################################
# Go
#
threshold=7                           # % usage above which we will delete
logfiles='/logs/abc/abc.log.*'        # ...log files matching this pattern

disk_space_monitor "$threshold" "$logfiles"
    
por 26.07.2016 / 11:21