Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created March 16, 2014 08:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/9580138 to your computer and use it in GitHub Desktop.
Save komasaru/9580138 to your computer and use it in GitHub Desktop.
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