Last Updated: February 25, 2016
·
795
· becreative-germany

Statistic about full filesystems

Example:
df | awk -f filesystem_stat | sort -r -n -t"," -k3 | tr "," "\t"

df = disk free command display all mounted filesystems
| = pipe short a redirection
sort = sort all data in numerical order (-n) and reverse 'descending' it (-r) and use a comma as seperator and sorted only the third column
tr = translate or delete characters in our case replace comma with a tabulator 'just for better look'

#Executes only at the beginning
BEGIN {

    #Counter variable for warnings/notices (additionally)
    warnings = 0
    notices = 0
}

#regex column 1 and must begin with at least on of these regexs  /<regex>/, ^ = must begin with
$1 ~ /^\/dev\// || $1 ~ /^UUID=/ || $1 ~ /^LABEL=/ || $1 ~ /^rootfs/ {


#Extract the number from the percentage 
storage[0] = "" #array deklarieren
founded = match($5, /^[0-9]+/, storage ) #Storage read out

#First condition if full greater than 90% 
if(founded && storage[0] >= 90 ){ 
print ">= 90%\t\t,"$1","$5 #Printing
warnings++ #Increment warning counter

}

#Second condition if full greater than 80% but lower than 90%
if(founded && storage[0] >= 80 && storage[0] < 90 ){ 
print ">= 80% and < 90%,"$1","$5 #Printing
notices++ #Increment notice counter
}

#if no critical filesystem was founded
if(founded == 0){
    printf "No critical filesystem founded!\n"
}

}
#Executes only at the end
END {
#Print Footer
printf "Finish! - Warnings : %d , Notices: %d | by Dustin Deus" , warnings, notices
}