2021-10-30 23:14:10 +00:00
|
|
|
#!/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
|
2021-11-01 19:00:04 +00:00
|
|
|
MyDfCnN='df -hTx tmpfs -x devtmpfs -x fuse -x nfs4' ## df - command - w/o *tenpfs, fuse and nfs4
|
|
|
|
#MyDfC="${MyDfCnN}" ## uncomment to overwrite wit additional fuse and nfs4 filesystems
|
2021-10-30 23:14:10 +00:00
|
|
|
MyDfAlert1=80 ## alert level of df
|
|
|
|
MyDfAlert2=90 ## critical alert level of df
|
|
|
|
|
2021-11-01 19:00:04 +00:00
|
|
|
## Escape sequences for color
|
|
|
|
esc=$(echo -en "\033") ## define esc sequence
|
|
|
|
dick="${esc}[1m" ## define bold sequence
|
|
|
|
rot="${esc}[1;31m" ## define red sequence
|
|
|
|
gruen="${esc}[1;32m" ## define green sequence
|
|
|
|
gelb="${esc}[1;33m" ## define yellow sequence
|
|
|
|
blau="${esc}[1;34m" ## define blue sequence
|
|
|
|
lila="${esc}[1;35m" ## define purple sequence
|
|
|
|
norm=$(echo -en "${esc}[m\017") ## define default sequence
|
2021-10-30 23:14:10 +00:00
|
|
|
|
|
|
|
## 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
|
2021-11-01 19:00:04 +00:00
|
|
|
elif [ $(( ${MyDfUsage} )) -ge ${MyDfAlert2} ]; then ## If critical level excited
|
2021-10-30 23:14:10 +00:00
|
|
|
echo -e ${rot}"${MyOutput}"${norm} ## Echo in red
|
2021-11-01 19:00:04 +00:00
|
|
|
elif [ $(( ${MyDfUsage} )) -ge ${MyDfAlert1} ]; then ## If alert level excited
|
|
|
|
echo -e ${gelb}"${MyOutput}"${norm} ## Echo in yellow
|
2021-10-30 23:14:10 +00:00
|
|
|
else ## default
|
|
|
|
echo -e ${gruen}"${MyOutput}"${norm} ## Echo in green
|
|
|
|
fi
|
|
|
|
done
|