Shell Script 監測硬碟使用量

https://www.phpini.com/linux/shell-script-check-harddisk-usage

Shell Script 監測硬碟使用量
#!/bin/bash

toemail="you@youremail.com"
alert=90

df -H | grep -vE ‘^Filesystem|tmpfs’ | awk ‘{ print $5 " " $6 }’ | while read output;
do
usepercent=$(echo $output | awk ‘{ print $1}’ | cut -d’%’ -f1 )
partition=$(echo $output | awk ‘{ print $2 }’ )
if [ $usepercent -ge $alert ]; then
echo "$(date): $(hostname) Disk Space Alert: \"$partition ($usepercent%)\"" |
mail -s "$(hostname) Disk Space Alert" $toemail
fi
done

0 0 * * * /path/to/check-disk.sh > /dev/null 2>&1

本篇發表於 未分類 並標籤為 。將永久鍊結加入書籤。

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>