my-scripts/dfc.sh

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, fuse and nfs4
#MyDfC="${MyDfCnN}" ## uncomment to overwrite wit additional fuse and nfs4 filesystems
MyDfAlert1=80 ## alert level of df
MyDfAlert2=90 ## critical alert level of df
## 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
## 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 excited
echo -e ${rot}"${MyOutput}"${norm} ## Echo in red
elif [ $(( ${MyDfUsage} )) -ge ${MyDfAlert1} ]; then ## If alert level excited
echo -e ${gelb}"${MyOutput}"${norm} ## Echo in yellow
else ## default
echo -e ${gruen}"${MyOutput}"${norm} ## Echo in green
fi
done