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"