cat log_file_viewer.sh
>>
#################################
# Multiple Log File Viewer (Linux Bash)
# Programmed By DanBrother
#################################
#!/bin/bash
function pause(){
   read -p "$*"
}

RED='\033[0;31m'
Light_Green='\033[0;32m'
Light_Cyan='\033[0;36m'
Yellow='\033[0;33m'
NC='\033[0m' # No Color


#  declare -a arr_log=($(ls -1 /data/sample/sample*.log))     # if logs are from the same directory

# Specify all collected log files bellow
declare -a arr_log=(
"/home/oracle/sh/rman_clear_arc_dataplatform.log"
"/data1/oracle_backup/backup_datapaltform_oracle.log"
"/home/oracle/sh/backup_metadata.log"
"/home/oracle/SQL_Tuning/housekeeping/adump_purge.log"
"/home/oracle/CheckUp/etl_checkup_daily.log"
"/home/oracle/CheckUp/etl_checkup_hourly.log"

)

function display_menu(){
    clear
    printf "${RED}===============================   Log File Viewer   ===============================\n"
    option=0
    for ((idx=0; idx<${#arr_log[@]}; idx++)); do
         let option=$option+1;
         printf "=======>   ${Yellow}$option) ${arr_log[idx]} ${RED}\n"
    done
    last_file_index=$option;
    let option=$option+1;
    all_files_index=$option;
    printf "=======>   ${Yellow}$option) All Files ${RED}\n"
    let option=$option+1;
    exit_index=$option;
    printf "=======>   ${Yellow}$option) Exit ${RED}\n"
    printf "===================================================================================${Light_Green}\n"
}

while true; do
  option_flag=true
  while ($option_flag) ; do
    display_menu
    printf "Please select the option : "
    read -r n

    if ! [[ "$n" =~ ^[0-9]+$ ]]
    then
       echo "*** Error: input contains non-numeric characters. Press enter to continue !! ***"
       pause
    elif [ "$n" -le $last_file_index ] ;
    then
      option=0
      for ((idx=0; idx<${#arr_log[@]}; idx++)); do
           let option=$option+1;
           if [ "$option" = "$n" ]
           then
              cur_file=${arr_log[idx]}
              option_flag=false
           fi
      done
    elif [ "$n" = "$all_files_index" ] ;
    then
       option_flag=false
    elif  [ "$n" = "$exit_index" ] ;
    then
       printf "${NC}"
       exit
    else
       echo "*** Invalid option. Press enter to continue !! ***"
       pause
       option_flag=true
    fi
  done
  read -p "Please specify how many rows to view the log. [30]: " rows
  rows=${rows:-30}
  if [ "$n" = "$all_files_index" ]
  then
      for i in "${arr_log[@]}"
      do
        display_menu
        printf "================================================================================${Light_Green}\n"
        printf "[ ${Yellow}$i${Light_Green} ]\n"
        printf "================================================================================${Light_Green}\n"
        tail -n $rows $i
        printf "\n"
        pause `printf "${Light_Cyan}********* Press [Enter] key to continue... *********${NC}"`
        clear
      done
  else
    printf "================================================================================${Light_Green}\n"
    printf "[ ${Yellow}$cur_file${Light_Green} ]\n"
    printf "================================================================================${Light_Green}\n"
    tail -n $rows $cur_file
    printf "\n"
    pause `printf "${Light_Cyan}********* Press [Enter] key to continue... *********${NC}"`
  fi
done

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 DanBrother 的頭像
    DanBrother

    DanBrother的部落格

    DanBrother 發表在 痞客邦 留言(0) 人氣()