对log进行shell方法处理
2016-04-01 00:00
423 查看
一、功能描述
对log进行数据筛取,用切割的方式,获取record_time、function_name、Error_state、client_ip、tv_id、description等数据并插入到本地数据库的error_log表中
二、log模型
[2016-03-09 16:54:05:726] HttpSendLiveStream ERROR!!
[473 58.254.216.34:18297 TV4016]:: caught up by live stream! curr:17775[19886->19885]
[2016-03-09 16:54:07:219] LiveStateCheck:: TV6047 not received pkt for 15 seconds!!
[2016-03-09 16:54:07:951] LiveStateCheck:: TV6046 not received pkt for 15 seconds!!
[2016-03-09 16:54:08:105] HlsCheckStealingLink:: HLS Relay :client 209.126.64.42 is stealing!
三、完整代码
对log进行数据筛取,用切割的方式,获取record_time、function_name、Error_state、client_ip、tv_id、description等数据并插入到本地数据库的error_log表中
二、log模型
[2016-03-09 16:54:05:726] HttpSendLiveStream ERROR!!
[473 58.254.216.34:18297 TV4016]:: caught up by live stream! curr:17775[19886->19885]
[2016-03-09 16:54:07:219] LiveStateCheck:: TV6047 not received pkt for 15 seconds!!
[2016-03-09 16:54:07:951] LiveStateCheck:: TV6046 not received pkt for 15 seconds!!
[2016-03-09 16:54:08:105] HlsCheckStealingLink:: HLS Relay :client 209.126.64.42 is stealing!
三、完整代码
#/bin/bash # # Script: log_run_shell # Author: Charlotte # Date2016/3/29 # # Platform: Linux # # ################################################## # Define files and variasles here ##################################################
# id time cdn_path=`pwd` ID="0" sign="0" touch "$cdn_path/"cdn.txt :> "$cdn_path"cdn.txt
HOSTNAME="127.0.0.1" PORT="3306" USERNAME="root" PASSWORD="123456" DBNAME="operation_monitor" TABLENAME="error_log"
################################################## # Beginning of main ##################################################
while read LINE do if [ $sign = "1" ] ; then # record no.2 # if [${LINE:1:2} = "["]; then IP=`echo $LINE | awk -F ' ' '{print $2}' | awk -F ':' '{print $1}'` tv_key=`echo $LINE | awk -F '[] ]' '{print $3}'` duration_time=`echo $LINE | awk -F '[:[]' '{print $6}'` # fi description=${LINE#*::} sign="0" insert_sql="insert into ${TABLENAME}(id,function_name,description,record_time) values('','$model','$description',$record_time)" mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${insert_sql}" else # record no.1 echo $LINE | grep -E "ERROR|FATAL|WARNING" 1>/dev/null if [ $? != "0" ] ; then continue fi record_time=`echo $LINE | awk -F '[]. :[-]' '{print $2$3$4$5$6$7}'` model=`echo $LINE | awk -F ' ' '{print $3}'` state=`echo $LINE | awk -F '[ !]' '{print $4}'` sign="1" ID=$[($ID+1)] fi done <"$cdn_path/"record_model.log
# End of script
相关文章推荐
- 登录式shell的执行顺序及简单应用
- shell 之 bash 与sh 区别
- bash算术求值和errexit陷阱
- shell脚本相关
- 2款XSHELL配色方案及导入配色方案的方法
- HDU2149——Public Sale(Bash Game巴什博奕)
- Linux Shell 学习笔记1:Shell程序的运行及基本介绍
- ORMLite的几个关键注解的使用说明
- 有关bash的一些常识
- hbase shell基础和常用命令详解
- hbase shell - 使用filter进行scan
- 【转】LINUX Shell 下求两个文件交集和差集的办法
- shell 基础语法
- shell脚本实例
- linux下用shell来 CURL POST JSON 数据遇到的问题
- bash脚本编程(三)
- Shell for循环用法总结
- shell多线程
- adb shell 获得活动窗口信息
- 使用xshell链接本地虚拟机中的Linux