Скрипт для удаления файлов на основе порогового значения [дубликат]

while read -r f1 fpath; do
   printf '%s\t%s\n' "$fpath" "$f1"
done < file1

Я не уверен, что вам нужно, но вы делаете это намного сложнее, чем нужно.

Результат:

aaa/aaa 111
b b/bbb 222
ccc/c c 333
d d/d d 444
1
18.11.2018, 19:27
1 ответ

Я бы выбрал что-то вроде этого

#!/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"
1
27.01.2020, 23:47

Теги

Похожие вопросы