Request错误监控脚本
2015-09-19 18:23
495 查看
第一次写的脚本
1#!/bin/bash 2 #This is a ShellScript For HTTP ERR count script 3 #2014-11-10 4 5 #调用脚本 6 source /leave/boman/script/functions.sh 7 8 #日志目录 备份目录 删除备份日志的记录 9 log_path=/leave/boman/wlptest/monitor.txt 10 backUp_path=/leave/boman/wlptest/logLogs 11 mailAddsFile=/leave/boman/script/email/mailAdds.txt 12 13 #请求错误出现次数的阀值 14 errLimitNum=5; 15 16 #根据错误类型和log文件路径获取错误的数量 17 function countNumOfErrType(){ 18 fileLocation=$1 19 type=$2 20 count=`cat $fileLocation | grep $type | wc -l` 21 echo $count 22 return $count 23 } 24 25 #统计错误数量 26 count404=`countNumOfErrType $log_path 404` 27 count500=`countNumOfErrType $log_path 500` 28 count403=`countNumOfErrType $log_path 403` 29 count=$[ $count403+$count404+$count500 ] 30 31 #超过n次发送邮件 32 content="访问错误404:$count404次,500:$count500次,403:$count403次,超过5次请排查错误" 33 theme="log_errNum_count_info" 34 35 if [[ $count != '' ]] ; then 36 if [ $count -ge $errLimitNum ] ; then 37 echo "err over $errLimitNum times,deal with it" 38 sendMail "$theme" "$content" "$mailAddsFile" 39 if [[ $? -eq 0 ]]; then 40 echo "发邮件成功!" 41 else 42 echo "发邮件失败!" 43 fi 44 fi 45 fi 46 47 #复制日志内容到备份文件夹下 清空日志内容 48 nowTime=`date '+%Y-%m-%d-%H-%M-%S'` 49 cp $log_path $backUp_path/$nowTime.txt 50 echo > $log_path 51 if [[ $? -eq 0 ]]; then 52 echo "备份清空成功!" 53 else 54 echo "备份清空失败!" 55 fi 56 57 #删除备份日志中两天前的日志 58 find $backUp_path -mmin +1 | xargs rm -rf 59 if [[ $? -eq 0 ]]; then 60 echo "Delete Old ErrBeifenFile Success!" 61 else 62 echo "Delete Old ErrBeifenFile Failed! or have not to need delete" 63 fi
相关文章推荐
- 优秀的UI插件
- mysql导入数据库出现:Incorrect string value: '\xE7\x82\xB9\xE9\x92\x9F' for column 'chinese' at row 1
- CEGUI的安装简要总结
- java学习笔记图形程序设计及GUI应用小结(2)
- ios开发UIImage imageNamed方法的误用
- iOS UI基础-10.0 QQ聊天布局之键盘及文本使用
- UVA - 11039 Building designing
- UIAutomator源码分析之启动和运行
- iOS8下,使用UIAlertControllerStyleActionSheet时发生崩溃,怎么办?
- execute、executeQuery和executeUpdate之间的区别
- iOS8下,UIImagePickerController的popoverPresentationController为空,要怎么获取?
- UITableView/UITabBarController/可视化编程/自动布局
- iOS 使用UIDocumentInteractionController类打开文件
- java学习笔记图形程序设计及GUI应用小结(1)
- UEditor和CKEditor配置上传图片,视频,附件
- 客户端GUI程序开发漫谈
- UIView 中autoresizingMask的属性
- 点击UITableView的cell展开收缩
- UIScrollView pagingEnabled自定义翻页宽度
- 多线程工具之NSOperationQueue