加载中…
个人资料
狗窝
狗窝
  • 博客等级:
  • 博客积分:0
  • 博客访问:0
  • 关注人气:0
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:大 中 小

[转]shell脚本自动监控日志文件,发现关键词发送邮件模板

(2013-03-04 16:34:35)
分类: 工作
monitor
#!/bin/bash
#Usage: Excute the java class and remove the specified productname file #
#author:#
#2009.11.01#


#Specife this file usage

usage(){
    echo "####################################################"
        echo "# Monitor xxx.log and send info to DBA             #"          
        short_usage
}

short_usage(){
    
        echo "# Usage: ./monitor -p filepath                     #"
        echo "####################################################"
    exit 1
}





#检测和获取参数

if [ $# = 0 ];then
      usage
fi

while getopts p: OPTION
do
case $OPTION in
       p)filepath=$OPTARG
       ;;
       \?)usage
       ;;
esac
done


 
mail_to=yourmail@xx.xx
mail_file=archive_alarm

echo "`date "+%Y-%m-%d %H:%M:%S"` " > $mail_file

if cat $filepath| grep -q "keyword";then

    echo keyword >> $mail_file                        

 fi


if [ [ -f $mail_file ] ] ; then

    cat $mail_file | mail -s "alarm " $mail_to

fi

0

阅读┊ 收藏 ┊ 喜欢▼ ┊打印┊举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有