38 lines
1.8 KiB
Bash
Executable file
38 lines
1.8 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# df with some options and colored if Alert levels are exceeded
|
|
# (c) GPL by Ulf Bartolomäus
|
|
VERSION="Version 0.1.1 from 13.02.2021"
|
|
|
|
# 0.1.1
|
|
# Initial based on whatch_new
|
|
|
|
MyDfC='df -hTx tmpfs -x devtmpfs' ## df - command - w/o *tenpfs
|
|
MyDfCnN='df -hTx tmpfs -x devtmpfs -x fuse -x nfs4' ## df - command - w/o *tenpfs, fusa and nfs4
|
|
#MyDfC="${MyDfCnN}" ## zweite verusion statt erste
|
|
MyDfAlert1=80 ## alert level of df
|
|
MyDfAlert2=90 ## critical alert level of df
|
|
|
|
## Escape secences for color
|
|
esc=$(echo -en "\033") ## define esc secence
|
|
dick="${esc}[1m" ## define bold secence
|
|
rot="${esc}[1;31m" ## define red secence
|
|
gruen="${esc}[1;32m" ## define green secence
|
|
gelb="${esc}[1;33m" ## define yelow secence
|
|
blau="${esc}[1;34m" ## define blue secence
|
|
lila="${esc}[1;35m" ## define purple secence
|
|
norm=$(echo -en "${esc}[m\017") ## define default secence
|
|
|
|
## DiskFree (only if not the same device => uniq check first 40 characters
|
|
${MyDfC} | uniq -w40 | while read MyOutput; do ## Execute df and filter doublicates - for each row stored in MyOutput
|
|
MyDfUsage=$(echo ${MyOutput} | awk '{ print $6}' | cut -d'%' -f1 ) ## Search Usage in %
|
|
if [[ ! $( echo "${MyDfUsage}" | grep [[:digit:]] ) ]] ; then ## If first row
|
|
echo -e ${dick}"${MyOutput}"${norm} ## Echo in bold
|
|
elif [ $(( ${MyDfUsage} )) -ge ${MyDfAlert2} ]; then ## If critical level excided
|
|
echo -e ${rot}"${MyOutput}"${norm} ## Echo in red
|
|
elif [ $(( ${MyDfUsage} )) -ge ${MyDfAlert1} ]; then ## If alert level excided
|
|
echo -e ${gelb}"${MyOutput}"${norm} ## Echo in yelow
|
|
else ## default
|
|
echo -e ${gruen}"${MyOutput}"${norm} ## Echo in green
|
|
fi
|
|
done
|