linux 监控磁盘空间脚本

 

linux 监控磁盘空间脚本

#!/bin/bash

set -x

init()

{

  IPADD=`ifconfig|grep 192.168|awk '{print $2}'|sed 's/addr://g'`;

  NOWTIME=`date+%F-%H:M`;

  MAILTO="****************@gmail.com";

  MAIL_SUB="!**Report --Disk Capacity Report $NOWTIME**!";

  tmpfile=/tmp/df.txt;

}

mhead()

{

  echo "________________________________">$tmpfile

  echo "From:$IPADD">>$tmpfile

  echo "State :Report">>$tmpfile

  echo "ReportVBy:{GetProperty(Content)}">>$tmpfile

  echo "DateTime:$NOWTIME">>$tmpfile;

  echo "Info :codefei">>$tmpfile

  echo "________________________________">>$tmpfile

}

smail()

{

  mail -s "$MAIL_SUB" $MAILTO<$tmpfile

}

init;

for x in `df|grep /dev |awk '{print $5}'|sed 's/%//g'`

do

if [ $x -gt 60 ];then

mhead;

df -h>>$tmpfile;

smail;

exit 0;

fi

done

你可能感兴趣的:(linux,脚本,监控,磁盘)