檢查硬碟使用率

# 當發現硬碟使用率大於80%時,通知維護人員
if [ `/bin/df -h | awk 'NR==4 {print $5}' | sed 's/%//'` -ge 80 ]
then
    (
      echo To: cowman.chiang@udngroup.com
      echo From: Splunk@udnlap01
      echo Subject: Splunk Server disk usage > 80%
      echo
    ) | /usr/sbin/sendmail -t
fi

原本df輸出如下

[root@udnlap01 splunk_input_data]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p1      99G  3.8G   90G   5% /
tmpfs                 3.9G   72K  3.9G   1% /dev/shm
/dev/cciss/c0d0p3     286G  116G  156G  43% /home

所以是抓取第四行的第五個欄位,並將其%去掉

This entry was posted in Linux. Bookmark the permalink.

One Response to 檢查硬碟使用率

Comments are closed.