一个查看日志的脚本

一个查日志的脚本,用处不大,还需要完善

#!/bin/bash
#Write by [email protected]
#Date:2016-9-29
####################定义功能函数部分#####################
function print_error {
        printf "\033[32;1m使用方式:  $0 -a -b -c
        -a:根据关键字打印日志
        -b:根据时间打印日志
        -c:打印实时日志
        \033[0m\n"
        exit 1
}

function print_date {
        printf "\033[1;32m 输入日期 例:09 06\033[0m\n"
        read  m d
        if [ $m -gt 0 -a $m -lt 13 -a $d -gt 0 -a $d -lt 32 ];then
        printf "\033[1;32m 2016年$m月$d日\033[0m\n"
        else
        printf "\033[1;32m 请输入正确的日期\033[0m\n"
        exit 1
        fi
}

function print_apply {
        printf "\033[1;32m 输入需要查询的应用\033[0m\033[1;44;31;5m\n   actprovider   act   app   awardsgrant   bi\n   b   callback   credit   currentbao   fixedbao\n   growthpoint   mq   pay   pyramid   rest   rmi\n   sms   task   wap   web\033[0m\n"
        read  apply
        if [[ $applys =~ $apply ]] ;then
        printf "\033[1;32m 寻找$apply的日志\033[0m\n"
        else
        printf "\033[1;32m 请输入正确应用名\033[0m\n"
        exit 1
    fi
}

function print_key {
        printf "\033[1;32m 输入关键字\033[0m\n"
        read keyword
        cd /opt/logs/2016.$m.$d
        cat $apply.tomcat-catalina-out | grep -n $keyword
}

function print_time {
        cd /opt/logs/2016.$m.$d
        printf "\033[1;32m 输入时间 例:14 05\033[0m\n"
        read  H M
        if [ $H -ge 0 -a $H -le 23 -a $M -ge 0 -a $M -le 59 ];then
        printf "\033[1;32m $H时$M分\033[0m\n"
        else
        printf "\033[1;32m 请输入正确的时间\033[0m\n"
        exit 1
    fi
        nu1=$(cat $apply.tomcat-catalina-out | grep -n $H:$M: | awk 'NR==1{print}' | awk -F ":" '{print $1}')
        nu2=$[$nu1+500]
        cat $apply.tomcat-catalina-out | awk 'NR>nu1&&NR

你可能感兴趣的:(一个查看日志的脚本)