четверг, 16 сентября 2021 г.

Linux Bash check disk space

df --output=pcent / | tail -n +2 | tr -cd '0-9\n'

output available percent without header and symbol '%' - only number

#!/bin/bash

for mnt in / /var/log /var/www /mnt/shared; do

  chk_avail=`df --output=pcent $mnt | tail -n +2 | tr -cd '0-9\n'`

  flg=`echo $(( 100 - $chk_avail ))`

  if [ $flg -lt 15 ]; then

    echo 'Dataserver lack of free space, only '$flg' percent available in '$mnt' partition' | mail -s 'Dataserver lack of free space' alerts@gmail.com

  fi

done