需求:从日志信息中提取特定时间范围内的日志,并将其发送至远程主机上
分析:一般的需求只是以两个特定的时间点做要求,比如说12:00:00到13:00:00这两个准确时间点之间的日志信息,同时日志中肯定是存在这两个时间点的
本需求只是求个范围值,比如说12点到13点之间的日志信息,并不能确定日志中有这两个时间点,也就说有可能只是12:00:01这样的时间点
#!/bin/bash
#scp today's error.log and profler.log to the mailserver
#author:liangaoxin
#date:20101231
<!--more-->
#working directory
pwd=/u01/lgx/temp
#destination's IP
dst=192.168.33.41
#foemat the date
today=`date '+%Y-%m-%d'`
if [ -e app.log.${today} ]
then
###截取6点和8点之间的日志信息,通过来取得时间,如06:00:01,更详细的日志信息格式就不多写了,类似于apache一般的access_log,本脚本也只是个思路而已
start=`cut -c12-19 app.log.{today}|grep -n "..:..:.."|awk -F: '$2<9 && $2>05 {print $1}'|head -n1`
stop=`cut -c12-19 app.log.{today}|grep -n "..:..:.."|awk -F: '$2==9 {print $1}'|head -n1`
sed -n "${start},${stop-1}p" app.log.${today} >app.log.${today}.send
scp -p /u01/log/temp/app.log.${today}.send lgx@${dst}:/home/lgx/$(hostname)/
fi
要是指定特定时间段内日志信息的提取会简单的多,如下 sed -n '/15:32:30/,/16:12:09/p' access_log >log.txt
祝大家新年快乐~^_^
发表在《
发表在《
发表在《
我好像有些洁癖……总是喜欢搞清理……连日志都不放过……
[回复]
freetstar
回复:
一月 2nd, 2011 at 8:11 下午
什马意思阿
[回复]
grep -n 是亮点
[回复]
freetstar
回复:
一月 1st, 2011 at 3:27 下午
@ihipop, yes
[回复]
[回复]
freetstar
回复:
十二月 31st, 2010 at 10:31 下午
@dorole, 新春快乐
[回复]
freetstar
回复:
十二月 31st, 2010 at 10:31 下午
@dorole, 准确的说是新年快乐哈
[回复]
dorole
回复:
十二月 31st, 2010 at 10:34 下午
@freetstar, 也对,年字顺口多了
[回复]
freetstar
回复:
十二月 31st, 2010 at 10:41 下午
@dorole,
愿大家万事如意
[回复]
我用过这个调出网络流量
cat /proc/net/dev | grep eth0 | sed ‘s=^.*:==’ | awk ‘{ print $1 }’
[回复]
freetstar
回复:
十二月 31st, 2010 at 10:19 下午
@婉秋, 额…这个net/dev我得好好研究下,看样子是网络都走的他阿
[回复]
哇哦 你这个代码宽度超出了分辨率了 太宽了 把页面给弄得很宽
[回复]
freetstar
回复:
十二月 31st, 2010 at 9:05 下午
@丕子, 我准备换主题。。。
[回复]
Mucid
回复:
一月 1st, 2011 at 10:07 上午
@freetstar, 我开着proxy,所以有时候css加载的慢,就会页面超出……
[回复]