2009年7月16日 星期四

偵測硬碟使用空間並發出警告信

Linux Shell Script
當硬碟使用空間大於90%時就發出E-mail通知信


#!/bin/bash
df -h | grep -vE '^Filesystem' | awk '{ print $5 " " $6 }' | while read output
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 90 ]; then
echo "Running out of space "$partition $usep%" on $(hostname) as on $(date)" | mail -s "Alert: Almost out of disk space $usep%" root
fi
done


再搭配Crontab就可以做出自動偵測.

HEMiDEMi Technorati Del.icio.us MyShare個人書籤 Yahoo

0 意見: