tomcat的catalina.out擷取日誌指令碼

wangzhensheng發表於2008-04-27

#!/bin/sh
log_file="$1"
date="$2"
begin_time="$3"
end_time="$4"
new_log="`hostname -i | awk -F[.] '{print $4}'`"

if [ $# -lt 4 ]; then
echo "`basename $0`: useing log_file(catalina.out) DATE(yyyy-m-d) begin_time(hh:mm) end_time(hh:mm) "
else
begin_grep="${date} ${begin_time}"
echo ${begin_grep}

end_grep="${date} ${end_time}"
echo ${end_grep}

begin_lines_num=`grep -n "${begin_grep}" ${log_file} | head -1 |awk -F'[:t]' '{print $1}'`
echo ${begin_lines_num}


end_lines_num=`grep -n "${end_grep}" ${log_file} | tail -1 |awk -F'[:t]' '{print $1}'`
echo ${end_lines_num}

lines=`expr ${begin_lines_num} - ${end_lines_num}`
echo ${lines}

head -${end_lines_num} ${log_file} | tail ${lines} >../logs/${new_log}_${begin_time}_${end_time}.log

fi

[@more@]

#!/bin/sh
log_file="$1"
date="$2"
begin_time="$3"
end_time="$4"
new_log="`hostname -i | awk -F[.] '{print $4}'`"

if [ $# -lt 4 ]; then
echo "`basename $0`: useing log_file(catalina.out) DATE(yyyy-m-d) begin_time(hh:mm) end_time(hh:mm) "
else
begin_grep="${date} ${begin_time}"
echo ${begin_grep}

end_grep="${date} ${end_time}"
echo ${end_grep}

begin_lines_num=`grep -n "${begin_grep}" ${log_file} | head -1 |awk -F'[:t]' '{print $1}'`
echo ${begin_lines_num}


end_lines_num=`grep -n "${end_grep}" ${log_file} | tail -1 |awk -F'[:t]' '{print $1}'`
echo ${end_lines_num}

lines=`expr ${begin_lines_num} - ${end_lines_num}`
echo ${lines}

head -${end_lines_num} ${log_file} | tail ${lines} >../logs/${new_log}_${begin_time}_${end_time}.log

fi

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8806316/viewspace-1003072/,如需轉載,請註明出處,否則將追究法律責任。

相關文章