Updated version of dfc.sh which are able to change the settings via
options
This commit is contained in:
parent
e18bc5ab5c
commit
3d0d21d6f1
1 changed files with 90 additions and 25 deletions
115
dfc.sh
115
dfc.sh
|
@ -1,37 +1,102 @@
|
|||
#!/bin/bash
|
||||
# df (= DiskFree) with some options and colored if Alert levels are exceeded
|
||||
#
|
||||
# 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"
|
||||
VERSION="$( basename $0 ) Version 0.1.2 from 03.11.2021"
|
||||
#
|
||||
# Input: -v : Version
|
||||
# -y YY : YY = alert level (yellow) in % (default = 80%)
|
||||
# -r RR : RR = critical alert level (red) in % (default = 90%)
|
||||
# Output: disk free information colored about mounted filesystems
|
||||
# Returnvalue: 0
|
||||
#
|
||||
# Changes:
|
||||
# 0.1.2
|
||||
# Some format improfements and adding from options
|
||||
# 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
|
||||
## Definitions
|
||||
#MyDfC='df -hT' ## df command: -h: human readeable, -T: show filesystem type
|
||||
MyDfC='df -hTx tmpfs -x devtmpfs' ## df -hT command: excluding *tenpfs
|
||||
#MyDfC='df -hTx tmpfs -x devtmpfs -x fuse -x nfs4' ## df -hT command: excluding *tenpfs, fusa and nfs4 filesystems
|
||||
|
||||
## 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
|
||||
MyDfAlert1=80 ## "yellow" for alert level for out of space
|
||||
MyDfAlert2=90 ## "red" for critical alert for out of space
|
||||
|
||||
## 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
|
||||
## 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
|
||||
|
||||
|
||||
## Shows the Version iformation
|
||||
do_version () {
|
||||
echo "* ${VERSION} *"
|
||||
}
|
||||
|
||||
## Show help
|
||||
do_usage () {
|
||||
echo "${dick}"
|
||||
echo "Usage: $( basename $0 ) [-Vvh] [-y AlertLevel] [-r CriticalAlertLevel] [dfOptions]"
|
||||
echo "This program provides the df (man df) information color by filling grade!"
|
||||
echo "${dick}${blau}"
|
||||
echo "This program is GPL (https://git.sp-codes.de/ub1x/my-scripts/src/branch/main/LICENSE)."
|
||||
echo "${norm}${dick}"
|
||||
echo "-V Version info - only"
|
||||
echo "-v Version info - aditional"
|
||||
echo "-h shows this help"
|
||||
echo "-y N percent value of alert level (marked in yellow) (default 80%)"
|
||||
echo "-r N percent value of critical alert level (marked in red) (default 90%)"
|
||||
# echo "dfOptions additional comand options"
|
||||
echo "${norm}"
|
||||
echo
|
||||
}
|
||||
|
||||
## Read options
|
||||
while getopts Vvhy:r: o; do
|
||||
case $o in
|
||||
V) do_version
|
||||
exit 0
|
||||
;;
|
||||
v) do_version
|
||||
;;
|
||||
h) do_usage
|
||||
exit 0
|
||||
;;
|
||||
y) if [ -n "$(( ${OPTARG} ))" ] ; then
|
||||
MyDfAlert1=$(( ${OPTARG} ));
|
||||
# echo "gelb von 80% auf ${MyDfAlert1}% geändert"
|
||||
fi
|
||||
;;
|
||||
r) if [ -n "$(( ${OPTARG} ))" ] ; then
|
||||
MyDfAlert2=$(( ${OPTARG} ));
|
||||
# echo "rot von 90% auf ${MyDfAlert2}% geändert"
|
||||
fi
|
||||
;;
|
||||
*) do_usage
|
||||
exit 10
|
||||
;;
|
||||
esac
|
||||
done
|
||||
#shift $(expr $OPTIND - 1)
|
||||
#MyDfC="${MyDfC} $*"
|
||||
|
||||
## DiskFree (only if not the same device => unique 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
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue