Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Bash script to check the capacity of disk partitions.
#!/bin/bash
# 閾値(%)
LIMIT=90
# メール件名
SUBJECT="[WARN] The capacity of the disk has decreased! - `hostname`"
# df コマンドの結果を1行ずつチェック
while read LINE
do
# パーセンテージ取得
PER=`echo $LINE | sed 's/^.* \([0-9]*\)%.*$/\1/'`
# 閾値を超えたら df コマンドの内容をメール送信
if [ $PER -gt $LIMIT ]; then
df -h | mail -s "$SUBJECT" root
break
fi
done < <(df | grep '[0-9]\{1,\}%')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment