0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

HDD容量監視スクリプト

Last updated at Posted at 2020-12-20

複数対象を監視する想定
監視対象が増減する際に変更が容易
監視パーティション使用率が80%以上になるとメールで通知
複数対象が閾値を超えてもメールは一通
メール本文に容量、使用率、対象パーティション記載

ファイル作成

$ touch chkdisk.sh
$ chmod 755 chkdisk.sh

スクリプト内容

# !/bin/bash

# 送信元アドレス
from="任意のアドレス"

# 送信先アドレス
to="任意のアドレス"

# メール件名
SUB="任意の件名"

# 閾値
LIMIT=80

# 監視対象
par=(par1 par2 par3)

# script
for i in ${par[@]}; do

# 閾値チェック
       chk=` df -h | grep $i | awk '{ print $5 }' | sed -e '$s/.$//' `
   if [[ $chk -ge $LIMIT ]]; then
       body+=("$(df -h | grep $i)\n")
   fi
done

# メール送信処理
echo -e "{$body[@]}" | awk '{ print $2,$5,$6 }' | mail -s "$sub" -r "$from" @to

cronの設定を任意の時間帯、曜日にして完了

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?