Chinaunix首页 | 论坛 | 博客
  • 博客访问: 710946
  • 博文数量: 160
  • 博客积分: 8847
  • 博客等级: 中将
  • 技术积分: 1656
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-25 16:46
个人简介

。。。。。。。。。。。。。。。。。。。。。。

文章分类

全部博文(160)

文章存档

2015年(1)

2013年(1)

2012年(4)

2011年(26)

2010年(14)

2009年(36)

2008年(38)

2007年(39)

2006年(1)

分类: LINUX

2007-05-19 16:45:47

vi Disk_check.sh

#!/bin/sh
#Check the HOME excist and if not excist,CREATE them.
home_dir="/var/report";
ip_list="$home_dir/ip_list";
lock=$home_dir/lock;

if [ -f "$lock" ]
then
        echo "This programe is already running.";
        exit 0;
fi
touch $lock;

Check_dir()
{
if [ ! -d "$home_dir" ]
then
        mkdir -p $home_dir;
fi

echo "  11 12 13 14 15 16
        71 72 73 74 75 76 77 78 79
        41 42
        91 92 93
        101 102 103 104
        111 112 113 114 115 116 131 132 133 134 135 136 137 138
        216 217
        21
        22
        201 202
        51 52
        191 192 193 194 195
        " > $ip_list;
}

Yesterday()
{
month=`date +%m`
day=`date +%d`
year=`date +%Y`
month=`expr $month + 0`
day=`expr $day - 1`
if [ $day -eq 0 ]; then
month=`expr $month - 1`
if [ $month -eq 0 ]; then
month=12
day=31
year=`expr $year - 1`
else
case $month in
1|3|5|7|8|10|12) day=31;;
4|6|9|11) day=30;;
2)
if [ `expr $year % 4` -eq 0 ]; then
if [ `expr $year % 400` -eq 0 ]; then
day=29
elif [ `expr $year % 100` -eq 0 ]; then
day=28
else
day=29
fi
else
day=28
fi
;;
esac
fi
fi
if [ $month -lt 10 ]
then
        month=0$month;
fi
if [ $day -lt 10 ]
then
        day=0$day;
fi
YESTIME="$year$month$day";
return $YESTIME;
}

#INIT
NOWTIME=`date +'%Y%m%d'`;
NOWTIME2=`date +'%Y-%m-%d %H:%M:%S'`;
DISK_FILE=$home_dir/disk_file.$NOWTIME;
PRE_IP="10.9.30.";
Yesterday;
Check_dir;
FILE="$home_dir/MAIL$NOWTIME";
echo > $home_dir/MAIL$NOWTIME;



echo "IPADD    :10.9.30.22" >> $FILE;
echo "TIME     :$NOWTIME2" >> $FILE;
echo "HOST     :fx-scr12" >> $FILE;
echo "STAT     :Report" >> $FILE;
echo "INFO     :JHFSYS/LiuJun" >> $FILE;
echo "" >> $FILE;
echo "+------------------------------------------------------------------------------------------+" >> $FILE;
echo "|10.9.30.xxx  |DiskSize(Bytes) |Used(Bytes)     |Avail(Bytes)   |Use |Full(DAY) |Load      |" >> $FILE;
echo "+------------------------------------------------------------------------------------------+" >> $FILE;

for ip in `cat $ip_list`
do
        DISK_SIZE_GB_NOWTIME=`ssh  dljroot@$PRE_IP$ip --  df -lh | sed -ne '/\/$/p'  | awk '{print $2}'`;
        DISK_SIZE_KB_NOWTIME=`ssh  dljroot@$PRE_IP$ip --  df -l  | sed -ne '/\/$/p'  | awk '{print $2}'`;
        DISK_USED_GB_NOWTIME=`ssh  dljroot@$PRE_IP$ip --  df -lh | sed -ne '/\/$/p'  | awk '{print $3}'`;
        DISK_USED_KB_NOWTIME=`ssh  dljroot@$PRE_IP$ip --  df -l  | sed -ne '/\/$/p'  | awk '{print $3}'`;
        DISK_Avail_GB_NOWTIME=`ssh  dljroot@$PRE_IP$ip -- df -lh | sed -ne '/\/$/p'  | awk '{print $4}'`;
        DISK_Avail_KB_NOWTIME=`ssh  dljroot@$PRE_IP$ip -- df -l  | sed -ne '/\/$/p'  | awk '{print $4}'`;
        DISK_PERCENT=`ssh  dljroot@$PRE_IP$ip          -- df -l  | sed -ne '/\/$/p'  | awk '{print $5}'`;
        LOAD=`ssh  dljroot@$PRE_IP$ip -- uptime | awk -F"average:" '{print $2}' | awk -F"," '{print $1}' |tr -d ' '`;
        echo $LOAD;
        echo $Avail_FILE_yeday;
        Avail_FILE_today="$home_dir/$ip.avail.$NOWTIME";
        Avail_FILE_yeday="$home_dir/$ip.avail.$YESTIME";
        #touch $Avail_FILE_today $Avail_FILE_yeday;

        if [ -n "`cat $Avail_FILE_yeday`" ]
        then
                Avail_FILE_yeday=`cat $Avail_FILE_yeday`;
        else
                touch $Avail_FILE_yeday;
                echo $DISK_Avail_KB_NOWTIME > $Avail_FILE_yeday;
                Avail_FILE_yeday=`cat $Avail_FILE_yeday`;
        fi
        echo $DISK_Avail_KB_NOWTIME > $Avail_FILE_today;
        Avail_FILE_today=`cat $Avail_FILE_today`;
        FULL_DAY=`expr $Avail_FILE_yeday - $Avail_FILE_today`;
        if [ $FULL_DAY -ne "0" ]
        then
                FULL_DAY=`expr $DISK_Avail_KB_NOWTIME / $FULL_DAY`;
        else
                FULL_DAY=100;
        fi
        if [ $FULL_DAY -lt 7 ] || [ $LOAD -gt 3 ]
        then

                echo "|`echo $PRE_IP$ip | awk '{printf "%-12s",$1}'` `echo $DISK_SIZE_KB_NOWTIME\($DISK_SIZE_GB_NOWTIME\) | awk '{printf "%-18s",$1}'` `echo $DISK_USED_KB_NOWTIME\($DISK_USED_GB_NOWTIME\) | awk '{printf "%-15s",$1}'` `echo $DISK_Avail_KB_NOWTIME\($DISK_Avail_GB_NOWTIME\) | awk '{printf "%-15s",$1}'` `echo $DISK_PERCENT | awk '{printf "%-4s",$0}'` `echo $FULL_DAY | awk '{printf "%-10s",$0}'` `echo $LOAD | awk '{printf "%-10s",$0}'`|--Warning!!" >> $FILE;
        else
                  echo "|`echo $PRE_IP$ip | awk '{printf "%-12s",$1}'` `echo $DISK_SIZE_KB_NOWTIME\($DISK_SIZE_GB_NOWTIME\) | awk '{printf "%-18s",$1}'` `echo $DISK_USED_KB_NOWTIME\($DISK_USED_GB_NOWTIME\) | awk '{printf "%-15s",$1}'` `echo $DISK_Avail_KB_NOWTIME\($DISK_Avail_GB_NOWTIME\) | awk '{printf "%-15s",$1}'` `echo $DISK_PERCENT | awk '{printf "%-4s",$0}'` `echo $FULL_DAY |awk '{printf "%-10s",$0}'` `echo $LOAD |awk '{printf "%-10s",$0}'`|" >> $FILE;
        fi
done
echo "+------------------------------------------------------------------------------------------+" >> $FILE;
        echo "$DISK_Avail_KB_NOWTIME" > $Avail_FILE_today;
        echo "$DISK_Avail_KB_NOWTIME" > $Avail_FILE_yeday;
#mv $Avail_FILE_today $Avail_FILE_yeday;
rm -rf ./[0-9]*
rm $lock;
#mailx  -s "Official Report of DISK partition On $NOWTIME2" xxx@email.com < $FILE;
mailx  -s "Official Report of DISK partition On $NOWTIME2"  xxx@email.com < $FILE;
exit 0;

阅读(2190) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~