日志中抓取特定字段shell脚本
2014-11-14 13:52
260 查看
老大让我把日志中的信息归类总结,好麻烦,写了这个脚本帮助工作。
需改进:1.抓取日志时间,只需要最后一次的时间,而这个脚本全部会抓到
2.需要两个时间的差值(比如15:23:34与23:23:34),没有完成
3.aix好不习惯
需改进:1.抓取日志时间,只需要最后一次的时间,而这个脚本全部会抓到
2.需要两个时间的差值(比如15:23:34与23:23:34),没有完成
3.aix好不习惯
#!/bin/ksh #进入目标文件目录 cd /user/lyb #输入标识字段 echo "开始时间" "结束时间" "客户组" "客户数量" >> /user/file10 #for i in "1 2 3 4 5 6 7 8 9 10 11 12" while [ true ] do echo "Please input the filename" #变量名为文件名,read -p在aix不好使 read filename #取出需要的字段,当文件中有多个相同字段时,没有判断条件 s1=`grep "接收到注册响应消息包,开始执行任务解析" $filename | sed 's/\..*//g'` s2=`grep "终止任务处理完毕,服务退出" $filename | sed 's/\..*//g'` s3=`grep "加载客户组.*用户" $filename | sed 's/^.*\[//g' | sed 's/\].*$//g'` s4=`grep "加载了.*个用户" $filename | sed 's/^.*\[//g' | sed 's/\].*$//g'` #将取出的字段输入到文件 echo "$s1" "$s2" "$s3" "$s4" >> /user /file10 done
#计算时间差sql语句 #select round((to_date('2014-11-13 12:22:23','yyyy-mm-dd hh24:mi:ss')-to_date('2014-11-13 12:12:32','yyyy-mm-dd hh24:mi:ss'))*24*60) time from dual; 版本V2.2 改进:增加计算s1与s2时间差语句 需改进:1.抓取日志时间,只需要最后一次的时间,而这个脚本全部会抓到 2.若s1时间格式为5:23:34(正常格式为12:23:34),新增语句会报错,需写判断语句改进(这个程序有97个bug,我解决掉一个,现在又117个bug了。。) 新增bug:1.一个进程运行时间超过00:00,会在另一个位置产生日志,这时脚本会报错 2.计算时间改为秒较为精确 #!/bin/ksh #进入目标文件目录 echo "Please input catalog:" read catalog cd $catalog #标识输出目录 echo "Please input the output_catalog:" read output_catalog #输入标识字段 echo "客户组" "开始时间" "结束时间" "客户数量" "消耗时间" >> "$output_catalog"/file10 #for i in "1 2 3 4 5 6 7 8 9 10 11 12" while [ true ] do echo "Please input the filename:" #变量名为文件名,read -p不好使 read filename #取出需要的字段,当文件中有多个相同字段时,没有判断条件 s1=`grep "接收到注册响应消息包,开始执行任务解析" $filename | sed 's/\..*//g'` s2=`grep "终止任务处理完毕,服务退出" $filename | sed 's/\..*//g'` s3=`grep "加载客户组.*用户" $filename | sed 's/^.*\[//g' | sed 's/\].*$//g'` s4=`grep "加载了.*个用户" $filename | sed 's/^.*\[//g' | sed 's/\].*$//g'` #s1时间格式为15:23:12,s11截取15,s12截取23 s11=`echo $s1 | cut -c 1-2` s12=`echo $s1 | cut -c 4-5` s13=`echo $s1 | cut -c 7-8` s21=`echo $s2 | cut -c 1-2` s22=`echo $s2 | cut -c 4-5` s23=`echo $s2 | cut -c 7-8` #将小时转换为秒,方便后面运算 s111=$(($s11 * 60 * 60)) s222=$(($s21 * 60 * 60)) #分钟转换为秒 s1111=$(($s12 * 60)) s2222=$(($s22 * 60)) #将小时和分钟转换为的秒和原本s1中的秒加起来,得到总的秒数 s14=$(($s111 + $s1111 + $s13)) s24=$(($s222 + $s2222 + $s23)) #计算开始至结束消耗时间 s5=$(($s24 - $s14)) #将取出的字段输入到文件 echo "$s3" "$s1" "$s2" "$s4" "$s5" >> /billing1/mibasbi1/file10 done #计算时间差sql语句 #select round((to_date('2014-11-13 12:22:23','yyyy-mm-dd hh24:mi:ss')-to_date('2014-11-13 12:12:32','yyyy-mm-dd hh24:mi:ss'))*24*60) time from dual;
相关文章推荐
- 自动发送密码抓取远程日志 Shell脚本实现代码
- Shell ftp 上传下载脚本 单独抓取文件中ip地址
- shell脚本迅速获取access日志中的某个参数
- shell脚本分析 nginx日志访问次数最多及最耗时的页面(慢查询)
- shell脚本实现自动压缩一天前的日志文件并传到ftp服务器上
- shell脚本传递参数的七个特定的变量
- 常用的几个shell脚本_2_查看日志
- 【shell脚本】匹配文件中特定的段落
- 监控数据库锁阻塞_机器连接数_警报日志的shell脚本 分享
- 小shell脚本-----每周压缩日志文件并删除未压缩的文件
- 日志文件分析shell脚本六次提速过程
- shell脚本迅速获取access日志中的某个参数
- 日志分析的shell脚本
- 日志压缩shell脚本
- linux+shell+脚本+过滤NetScreen防火墙日志
- shell脚本:自动内存监控及日志备份
- 检查字段并排序的shell脚本
- shell脚本分析 nginx日志访问次数最多及最耗时的页面(慢查询)
- shell脚本调试 -- 运行日志1
- 游戏日志自动抓取添加server脚本