Created
November 19, 2019 05:28
-
-
Save sl5net/19286d19b906a98030cfa838d5ae0187 to your computer and use it in GitHub Desktop.
Disk Info for Golang
This file contains hidden or 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 | |
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 | |
echo "$mounted_at" | sed -e 's/.*\//\/ /g' | |
echo " $blocks_avail = blocks_avail" | |
GBavail="$((($gb1+1)/1000000))" | |
if (( GBavail > 1 )); then | |
# echo "$gb1 = gb1" | |
# echo "$((($gb1+1)/1000000)) = GB avail" | |
echo " $GBavail GB free" | |
# mounted_short=$"$mounted_at" | sed -e 's/.*\///g' | |
fi | |
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 $filesystem" | |
echo "\_________________________________/" | |
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 $filesystem 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