如何在linux下用shell脚本编写实现这个功能:提取从现在到几个小时以前的的log记录?

比如我先grep抓取了一些带了某些关键字的log内容,格式如下:
Aug 13 10:04:05 00:B3:42:01:04:38 kernel: Con TargetName:iqn.2010-05.com.macrosan.target:macrosan-1.2810
Aug 13 10:04:05 00:B3:42:01:04:38 kernel: Incremented number of active iSCSI sessions to 1 on iSCSI Target Portal Group: 0
每行最前面是时间,也是我需要用到的筛选条件。

现在比如我要根据当前的系统时间提取5个小时以前一直到现在的上述所有log,该怎么写shell脚本?
我现在的思路是时间逐行做时间比对,大于5个小时的行就舍弃,小于等于5个小时的行就保留,但完全不知道这种比对的shell脚本该怎么写~~~~
或者各位如果有更好的思路麻烦也指明一下~~~

另外log的时间点不是连续的,可能好几分钟都没有记录信息,所以不能通过字符来筛选。
时间是变量,就是先获取当前的系统时间,然后往前推5小时,再根据这个时间点进行筛选。

这个问题我觉得用 awk 比较好实现。我试了一个,不过没找到怎么直接处理这个非数字的月份问题,使用数组来做了一个转换型烂,所以脚本长了一点。

下面是用 message 日志激租尺来做的测试,你可以换成你的日志文件来测试看看效果。

你可以更改 time_period 的值来达到想要其它时间内的日志。

# awk -F'[ :]+' 'BEGIN{time_period=5*3600; mon["Jan"] = 1; mon["Feb"] = 2; mon["Mar"] = 3; 明高mon["Apr"] = 4; mon["May"] = 5; mon["Jun"] = 6; mon["Jul"] = 7; mon["Aug"] = 8; mon["Sep"] = 9; mon["Oct"] = 10; mon["Nov"] = 11; mon["Dec"] = 12; now=systime();}; now - mktime("2013 " mon[$1] " " $2 " " $3 " " $4 " " $5) <= time_period {print}' messages
  Aug 13 05:15:01 test ntpdate[26717]: the NTP socket is in use, exiting
  Aug 13 05:25:01 test ntpdate[26782]: the NTP socket is in use, exiting
  Aug 13 10:05:01 test ntpdate[29013]: the NTP socket is in use, exiting
  Aug 13 10:10:01 test ntpdate[29076]: the NTP socket is in use, exiting