Menu / Log files - reading / display


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Menu / Log files - reading / display
# 1  
Old 02-23-2010
Menu / Log files - reading / display

So I'm pretty green still at this, and right now I don't even have the IF statements in just trying to get this part to work. I want to basically click optino 1,2,3,4 for which logs I want to search, and then be able to put in the variable I want to grep out? Sounds easy just not clear in my mind how to do it...

Code:
#!/bin/bash
 
while :
do
  clear
  # Display menu
  echo
  echo  "*************************************************************"
  echo  "Please enter which logs you are wanting to search?"
  echo  "  "
  echo
  echo  "*************************************************************"
  read option
  case "$option" in
      1)    echo "Read the A Logs "
            echo "Hit <Enter> to continue."
            read var1
            ;;
      2)    echo "Read the B Logs "
            echo "Hit <Enter> to continue."
            read var1
            ;;
      3)    echo "Read the C Logs "
            echo "Hit <Enter> to continue."
            read var1
            ;;
      4)    echo "Read the D Logs "
            echo "Hit <Enter> to continue."
            read var1
            ;;
clear ;;
echo "Please enter the filename or variable you would like to search for?"
echo
echo "Note this is case sensitive, and you do not have to use complete filenames "
echo
echo "However if you do it will make the search more specific. " read var2


Last edited by Scott; 02-23-2010 at 02:36 PM.. Reason: Please use code tags
# 2  
Old 02-23-2010
Quote:
Originally Posted by xgringo
So I'm pretty green still at this, and right now I don't even have the IF statements in just trying to get this part to work. I want to basically click optino 1,2,3,4 for which logs I want to search, and then be able to put in the variable I want to grep out? Sounds easy just not clear in my mind how to do it...

#!/bin/bash

while :
do
clear
# Display menu
echo
echo "*************************************************************"
echo "Please enter which logs you are wanting to search?"
echo " "
echo
echo "*************************************************************"
read option
case "$option" in
1) echo "Read the A Logs "
echo "Hit <Enter> to continue."
read var1
;;
2) echo "Read the B Logs "
echo "Hit <Enter> to continue."
read var1
;;
3) echo "Read the C Logs "
echo "Hit <Enter> to continue."
read var1
;;
4) echo "Read the D Logs "
echo "Hit <Enter> to continue."
read var1
;;
clear ;;
echo "Please enter the filename or variable you would like to search for?"
echo
echo "Note this is case sensitive, and you do not have to use complete filenames "
echo
echo "However if you do it will make the search more specific. " read var2
You should use the select loop which is an easy way to create menu.
# 3  
Old 02-23-2010
Something like this?

Code:
PS3="Select which log files you would like to search ? "

read myvar

select logfile in LogA LogB LogC LogD

do 
    cat /var/logA | grep "$logfile" | grep "$myvar"
    break
done



---------- Post updated at 03:26 PM ---------- Previous update was at 01:39 PM ----------

think I'm close? Help anyone?
Code:
#!/bin/ksh
#set -xv
PS3="Select which log files you would like to search ?"
 
LogA="~/ci*.log"
LogB="~/s2010*"
LogC="~/C2010*"
LogD="~/D2010*"
 
"Please enter the file name or variable that you would like to search for ?"
read myvar
 
select logfile in LogA LogB LogC LogD
 
do
cat $PS3 | grep "$myvar"
break
done



---------- Post updated at 05:05 PM ---------- Previous update was at 03:26 PM ----------

What if I said please? - I know you all probably think I'm a moron Smilie but could use the help.... if anyone has a minute.

---------- Post updated at 05:30 PM ---------- Previous update was at 05:05 PM ----------

I tried this too but the output keeps going in a loop I enter the input and keep going back to the menu.
Code:
#!/bin/sh
set -xv
while true; do
 
cat <<ENDINPUT
 
Menu of Options
 
1. Search a  Logs
2. Search b  Logs
3. Search c  Logs
4. Search d  Logs
 
ENDINPUT
 
echo "Please enter your choice:"
read option
 
echo "Please enter your search variable:"
read myvar
 
case "$option" in
        1)
                #grep *$myvar* /loga/a*.log
                ;;
        2)
                echo test 2
                ;;
        3)
                echo test 3
                ;;
        4)
                exit
                ;;
        *)
                echo "Use 1, 2, 3, or 4"
                ;;
esac
 
done


Last edited by Scott; 02-23-2010 at 04:39 PM.. Reason: Code tags please...
# 4  
Old 02-23-2010
It's in a loop, because you're using while true.

You need to tell it when to stop.

i.e.
Code:
#!/bin/sh
set -xv
while true; do
 
cat <<ENDINPUT
 
Menu of Options
 
1. Search a  Logs
2. Search b  Logs
3. Search c  Logs
4. Search d  Logs
 
ENDINPUT
 
echo "Please enter your choice:"
read option
 
echo "Please enter your search variable:"
read myvar
 
case "$option" in
        1)
                grep "$myvar" /loga/a*.log # <-- questionable use of grepping on multiple files
                break
                ;;
        2)
                echo test 2
                break # after each case - or use continue in your default case, and break after esac
                ;;
        3)
                echo test 3
                ;;
        4)
                exit
                ;;
        *)
                echo "Use 1, 2, 3, or 4"
                ;;
esac
 
done

# 5  
Old 02-24-2010
Code:
 syntax error at line 51: `end of file' unexpected

but there is no line 51 ?

Ok added the break to the first line everything looked good so I finished doing it to the other lines and got this?

Problem is there is no line 51 ?

---------- Post updated at 09:55 AM ---------- Previous update was at 09:54 AM ----------

And do you have a better suggestion for grepping multiple log files?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Gnome 3.28.3 menu item dissapears under the system menu

I installed CentOS 8 with Gnome 3.28.2 and I noticed that the "switch user" menu item disappeared from under the system menu of Gnome classic (Both X11 & Wayland). I checked google and this problem seems to have a history going back several releases of Gnome. Unfortunately, I never found a... (1 Reply)
Discussion started by: bodisha
1 Replies

2. Shell Programming and Scripting

Building a dynamic UNIX menu with input files

Hi! I am looking to build dynamic menu (named: lookup.sh) that reads a pipe delimited file for input. for example, contents of input.txt could be: user1|srv1 user3|srv1 user4|srv1 user2|srv2 I want the menu look like: 1) get password for user1 on srv1 2) get password for user3 on... (7 Replies)
Discussion started by: cpolikowsky
7 Replies

3. Shell Programming and Scripting

Display user selction from bash menu

I am trying to display the text the user selects from a bash menu. The below will display the menu and allow the user to enter a number, but will not display the choice selected. bash while true do printf "\n please make a selection from the MENU \n ... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Need help in create menu with 3 sub menu using the case command

hi all i am a newbie to this is there any examples on creating a main menu with 3 sub menu main menu -> option a , b and c a menu -> option 1 ,2 and 3 b menu -> option 1 ,2 c menu -> option 1 ,2 i am getting headache as my code kept getting unexpected EOF ---------- Post... (0 Replies)
Discussion started by: chercm
0 Replies

5. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

6. UNIX for Dummies Questions & Answers

write a program in c in unix that display the files(includ sub-direc and files within) in a sorted

the sorting is based on name of file, file size modification time stamps o f file it should dislay the output in the following format "." and ".." enteries should be ignored please give some idea how to do it (1 Reply)
Discussion started by: pappu kumar jha
1 Replies

7. Shell Programming and Scripting

Display a menu on bottom right of screen

Hi, I have a menu of around 10 lines with options. I want to display it in bottom right corner of screen for better display. I can do it with clear screen. But I don't want to use it, because it will clear the existing text. After one choice from menu is executed, the menu should just place... (3 Replies)
Discussion started by: som.nitk
3 Replies

8. Solaris

Disabled keystroke at the log-in menu

Hello I am unable to enter my password because the OS does not respond to my keystrokes in the password field at the log-in menu, even though it does in the username field. I have no clue how to troubleshoot this. Please help me out. Thank you (11 Replies)
Discussion started by: dai2809
11 Replies

9. Shell Programming and Scripting

creating a menu for recycling and permanently deleting files.

Trying to alias rm to move files to a hidden trash directory in the bash shell. I've tried to create this alias numberous ways and it's just not working. Here's what I've tried, anyone have any suggestions. alias rm='mv $* ~/.trash' alias rm= 'mv$* ~/.trash' things like that... I've also... (2 Replies)
Discussion started by: strmy_ngts
2 Replies
Login or Register to Ask a Question