From 3d36585f0a1927db59d3710df552fcc373b5f74a Mon Sep 17 00:00:00 2001 From: Jed Reynolds Date: Mon, 28 Dec 2020 22:05:05 -0800 Subject: [PATCH] check_large_files.bash: WIP core files --- check_large_files.bash | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/check_large_files.bash b/check_large_files.bash index daa63e68..1ec5db12 100755 --- a/check_large_files.bash +++ b/check_large_files.bash @@ -225,9 +225,12 @@ clean_old_kernels() { } clean_core_files() { - note "Cleaning core files WIP" + note "Cleaning core files..." + if (( ${#core_files[@]} < 1 )); then + return 0 + fi if (( $verbose > 0 )); then - printf "%s\n" "${core_files[@]}" + printf " %s\n" < <( echo "${core_files[@]}" | sort | uniq ) fi } @@ -294,8 +297,8 @@ survey_core_files() { cd / #set -x mapfile -t core_files < <(ls /core* /home/lanforge/core* 2>/dev/null) 2>/dev/null - if [[ $verbose = 1 ]]; then - printf "%s\n" "${core_files[@]}" + if [[ $verbose = 1 ]] && (( ${#core_files[@]} > 0 )); then + printf " %s\n" "${core_files[@]}" | head fi if (( ${#core_files[@]} > 0 )); then totals[c]=$(du -hc "${core_files[@]}" | awk '/total/{print $1}') @@ -407,11 +410,26 @@ disk_usage_report if (( ${#core_files[@]} > 0 )); then note "Core Files detected:" hr - #printf ' %s\n' "${core_files[@]}" - for core in "${core_files[@]}"; do - file $core - done + filestr="" + declare -A core_groups + set -e + # note that the long pipe at the bottom of the loop is the best way to get + # the system to operate with thousands of core files + while read group7; do + (( $verbose > 0 )) && echo -n '.' + group7="${group7%, *}" + group7="#${group7//\'/}" + [[ ${core_groups[$group7]+_} != _ ]] && core_groups[$group7]=0 + core_groups[$group7]=$(( ${core_groups[$group7]} + 1 )) + + done < <(echo "${core_files[@]}" | xargs file | awk -F": " '/execfn:/{print $7}') + echo "" + echo "These types of core files were found:" + while read group; do + echo " $group -> ${core_groups[$group]}" + done < <(echo "${!core_groups[@]}" | sort ) hr + set +x selections+=("c") fi