Exemplo:
df | awk -f filesystem_stat | sort -r -n -t “,” -k3 | tr “,” ” t”
df = comando de disco livre exibe todos os sistemas de arquivos montados
| = pipe curto um redirecionamento
classificar = classificar todos os dados em ordem numérica (-n) e inverter ‘descendente’ (-r) e usar uma vírgula como separador e classificar apenas a terceira coluna
tr = traduzir ou excluir caracteres no nosso caso, substituir vírgula com um tabulador ‘apenas para uma melhor aparência’
#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%tt,"$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
}