Created
November 19, 2019 22:21
-
-
Save sl5net/158d3cdb9f91f7482661874eb483e447 to your computer and use it in GitHub Desktop.
changed layout a bit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q | |
#maybe this script hangs: | |
#https://unix.stackexchange.com/questions/21199/why-is-df-hanging | |
clear | |
clear | |
toggle=1 | |
ignore_re='^Filesystem|tmpfs|cdrom' | |
# ignore_mounted_at='^\b(dev|run)\b' | |
ignore_filesystem='^\b(dev|run)\b' | |
while read -r line; do | |
[[ $line ]] || continue # skip empty lines | |
[[ $line =~ $ignore_re ]] && continue | |
read -r filesystem blocks_total blocks_used blocks_avail cap_pct mounted_at _ <<<"$line" | |
# below is a noop but makes set -x output more useful | |
: filesystem="$filesystem" blocks_total="$blocks_total" blocks_used="$blocks_used" blocks_avail="$blocks_avail" cap_pct="$cap_pct" mounted_at="$mounted_at" | |
usep=${cap_pct%"%"} # trim trailing % sign | |
usep=${usep%.*} # round (down) to nearest decimal | |
gb1=${blocks_avail%.*} # round (down) to nearest decimal | |
# [[ $mounted_at =~ $ignore_mounted_at ]] && continue | |
[[ $filesystem =~ $ignore_filesystem ]] && continue | |
# To do rounding up in truncating arithmetic, simply add (denom-1) to the numerator. | |
# gb=10000 + gb1 | |
# echo ">>>>> $mounted_at <<<<<" | sed -e 's/.*/[^\/]*/X/g' -e 's/[0-9]/N/g' | |
# sed -r 's/{{regex}}/{{replace}}/g' {{filename}} | |
# sed -r '/.*/g' {{$mounted_at}} | |
if((toggle=1)); then | |
newtoggle=0 | |
fi | |
if((toggle=0)); then | |
newtoggle=1 | |
fi | |
toggle=$newtoggle | |
if (( usep < 100 )); then | |
#echo $toggle | |
#echo $newtoggle | |
printf "$mounted_at" | sed -e 's/.*\//\/ /g' # printf ends without newline | |
echo " = $filesystem" | |
printf " $blocks_avail bytes" # printf ends without newline | |
GBavail="$((($gb1+1)/1000000))" | |
if (( GBavail > 1 )); then | |
# echo "$gb1 = gb1" | |
# echo "$((($gb1+1)/1000000)) = GB avail" | |
printf " = $GBavail GB free" | |
# mounted_short=$"$mounted_at" | sed -e 's/.*\//$/g' | |
fi | |
echo "" # just a newline | |
fi | |
if (( usep < 90 )); then | |
# mail -s "Alert: Almost out of disk space $usep%" name@asldfkjasöldkfjasöldkfsajf.com <<EOF | |
# $filesystem (mounted on $mounted_at) usage is $usep on $(hostname) as of $(date) | |
#echo " ^_^ $usep%used " | |
echo "\___^_^_$usep%used___________________/" | |
fi | |
if (( usep >= 90 && usep < 100 )); then | |
# layout=2 | |
isALERT=1 | |
# mail -s "Alert: Almost out of disk space $usep%" name@asldfkjasöldkfjasöldkfsajf.com <<EOF | |
# $filesystem (mounted on $mounted_at) usage is $usep on $(hostname) as of $(date) | |
echo " :-( $usep%used ALERT ALERT ALERT ALERT ALERT" | |
#echo "/^^^^^^^^^^^^^^^^^^^^^^" | |
echo "\_________________________________/" | |
fi | |
done < <(df -P) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment