With df -h
, awk
, tail
, tr
, how to create a custom "alert" column that should display one of the following indications for /mnt/hgfs :
edit: It's staying up.
df |awk -v threshold="75 81 96" -v message="Warning Critical Alarm" -v mnt="/mnt/hgfs" '
BEGIN {n=split(threshold, T); split(message, M)}
$NF == mnt {
for(i=n; i>0; i--)
if(int($5) > T[i]) {print M[i] ":", mnt, "usage:", $5; exit}
print mnt, "usage normal"
}'
split
lists into arrays; get the number of elements with n=split()
i
terate backwards over the T(hreshold) array, comparing the fifth column (Use%) to each value. If it's greater, print a warning message using the same value for the M(essage) array, then exit before other comparisons are performed.Solution for new requirements:
df |awk '
NR == 1 {alert="Alert"}
int($5) < 75 {alert=""}
int($5) > 75 {alert="Warning"}
int($5) > 81 {alert="Critical"}
int($5) > 96 {alert="Alarm"}
{printf("%-10s%s\n", alert, $0)}'