Calendar
数据载入中,请稍候......
Placard
数据载入中,请稍候......
Category
数据载入中,请稍候......
Latest Entries
数据载入中,请稍候......
Latest Comments
数据载入中,请稍候......
Last Messages
数据载入中,请稍候......
User Login
数据载入中,请稍候......
Links
Information
数据载入中,请稍候......
Search
Other


Welcome to my blog!
  linux性能检测结果发到指定的邮箱脚本
 

check.sh

#!/bin/bash

########################################################################
#This scripts is checking the i/o stat,vision 0.1Bate
#Author Hahazhu

########################################################################

#make the local language is chinese
export LANG=zh_CN.utf8
#make the around command path

ECHO=/bin/echo
SED=/bin/sed
AWK=/bin/awk
UPTIME=/bin/uptime
VMSTAT=/usr/bin/vmstat
FREE=/usr/bin/free
IPTABLES=/sbin/iptables
GREP=/bin/grep
TOP=/usr/bin/top
HEAD=/usr/bin/head
DF=/bin/df
CAT=/bin/cat

#check the iostat file is exits
#DATE_FILE=`date +%Y%m%d`
IOSTAT_FILE=./content.txt

if [ -e $IOSTAT_FILE ]
then
        echo "The iostat file is exits!"
else
        touch $IOSTAT_FILE
fi

#setup the time of the check

DATE=`/bin/date +%c`
$ECHO "   " >> $IOSTAT_FILE
$ECHO "   " >> $IOSTAT_FILE
$ECHO "本次检测的时间是:$DATE" >> $IOSTAT_FILE
$ECHO "-------------------------------------------------------------------------
--------------------" >>$IOSTAT_FILE

#check the cpu stat

$ECHO "当前时刻CPU使用状况如下:" >> $IOSTAT_FILE
$ECHO "`$TOP -b -n 1 |$GREP  Cpu`"   >> $IOSTAT_FILE
$ECHO "-------------------------------------------------------------------------
--------------------" >>$IOSTAT_FILE

#check the memory stat

$ECHO "当前时刻内存占用情况如下:" >> $IOSTAT_FILE
$ECHO "`$FREE |$GREP  -1 Mem |$HEAD -n 2 `" >> $IOSTAT_FILE
$ECHO "-------------------------------------------------------------------------
---------------------" >>$IOSTAT_FILE

#check the disk stat

$ECHO "当前时刻磁盘空间使用情况如下:" >> $IOSTAT_FILE
$ECHO "`$DF -h `" >> $IOSTAT_FILE
$ECHO "-------------------------------------------------------------------------
---------------------" >>$IOSTAT_FILE

#check the network stat

NETWORK_STAT=/proc/net/dev
$ECHO "当前时刻网络流量统计如下:"  >> $IOSTAT_FILE
$ECHO "`$CAT $NETWORK_STAT|$GREP -v lo |$GREP -v sit0 `" >> $IOSTAT_FILE
$ECHO "#########################################################################
#########################################################" >> $IOSTAT_FILE
./sendmail.pl
if [ $? = 0 ];then
  rm -f $IOSTAT_FILE
fi
exit 0

sendmail.pl

#!/usr/bin/perl
use Mail::Sender;
#my $mailtext = "Das is\'t der Text\nden ich gerne senden wuerde...";
my $sender = new Mail::Sender {
        smtp => 'smtp.163.com',
     from => 'zhuzhengju20@163.com',
     auth => 'LOGIN',
     authid => 'zhuzhengju20',
     authpwd => '指定邮箱密码',
     on_errors => undef,
} or die "Can't create the Mail::Sender object: $Mail::Sender::Error\n";
$sender->MailFile({to =>'hahazhu0634@126.com',
       subject => 'Here is the file',
       msg => "I'm sending you the list you wanted.",
       file => './content.txt'}) or print $Mail::Sender::Error;
$sender ->Close();

将性能检测的结果通过163.com发到126信箱!~将此两个脚本放到一个目录下,并且采用crond

[ 阅读全文 | 回复(0) | 引用通告 | 编辑

  Post  by  badboy 发表于 2007-9-28 15:49:00
发表评论:
数据载入中,请稍候......
数据载入中,请稍候......