磁盘空间满额报警shell脚本

转自苦咖啡。

http://alsww.blog.51cto.com/2001924/995169

 

#!/bin/sh
ip=`ifconfig|grep 192.168|awk '{print $2}'|sed 's/addr://g'`; ###过滤IP地址
time=`date +%F-%H:%M`;
mail_address="[email protected]";
tmpfile=/tmp/check-disk.tmp
a=`df -h | grep 'sda1'|awk '{print int($5)}'`; ###指定过滤的硬盘分区
touch /tmp/check-disk.txt

echo "From :$ip" > $tmpfile ###这里用“>”的意思是覆盖,保证每次发邮件的内容都是新的。
echo "DateTime:$time" >> $tmpfile
echo "Info :yourname" >> $tmpfile
echo "disk_status_use=$a%" >> $tmpfile

if [[ "$a" > 85 ]]; then ###指定分区的磁盘使用空间大于85%就报警
/bin/mail -s "warning ! $HOSTNAME disk is full !" $mail_address < $tmpfile
else
/bin/mail -s "$HOSTNAME disk is ok !" $mail_address < $tmpfile
fi

你可能感兴趣的:(shell脚本)