- 论坛徽章:
- 0
|
回复 1# spark_zhang
经过测试解决了跨小时问题:- #!/bin/awk -f
- BEGIN {
- while( ("date +%H:%M" | getline now) > 0 )
- {
- split( now, nowarray, ":" );
- }
- #nowarray[1]和[2]为当前时间小时和分钟
- #测试跨小时,设置当前分钟为3
- # nowarray[2]=3;
-
- start[1]=nowarray[1];
- start[2]=nowarray[2]-5;
- if( start[2]<0 )
- {
- start[1] = start[1]-1;
- start[2] = start[2]+60;
- }
- print "\n=============================================================="
- printf(" IP between %02d:%02d~ %02d:%02d\n",start[1], start[2], nowarray[1], nowarray[2] );
- print "==============================================================";
- #设置分割符
- FS=":";
- }
- {
- #$2为小时 $3为分钟
- # print $2":"$3;
- if( (start[1]==nowarray[1] && $3>=start[2] && $3<=nowarray[2]) || (start[1]+1==nowarray[1] && ($3>=start[2]||($2==nowarray[1]&&$3<=nowarray[2]))) )
- {
- split( $0, myarray, " " );
- print myarray[1], myarray[2];
- # print myarray[1];
- }
- }
- END {
- printf( "========================end-of-report=========================\n\n" );
- }
复制代码 |
|