Creating a menu from find

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a menu from find
# 1  
Old 11-08-2007
Creating a menu from find


I am wanting to create a menu that will list all the log files in a specific directory such as /apps/logs.

So it would be something like this:

print 'Select The Required Log File'
PS3='log? '
select choice in <this is to contain a list of files that are in a directory that would be populated using find /apps/logs>

any pointers would be most helpful.

# 2  
Old 11-08-2007

If it means that a user should be presented with a menu that lists all log file from /apps/logs and then he wants to view 'em selectively then I think we could:-
1) find /apps/logs -type f
2) Number the files from find's output and present the user
3) At the time they are displayed populate them in an array
4) display user to enter choice and pull that choice from array.

So it would be something like this in ksh ( I havenot tried it..chk for syntax errors)
for logfile in `find /apps/logs -type f `
echo "$logcnt : $logfile"
echo "Enter ur choice to view :\c"
read choice
cat "`cat ${logarr[$choice]}`"
I havenot provided any kind of locking facility here to handle errors. It 's just an idea
# 3  
Old 11-08-2007
select choice in $(find /apps/logs -type f -name '*log*')
   [ $choice ] && view $choice

# 4  
Old 01-22-2008
Thanks for the info. It is almost what I am looking for.
I am needing a menu with some dynamic items from find and other static items.
$DYNAMIC_ITEMS is where i will use my find, etc. For now i just set it.
The $DYNAMIC_ITEMS will be run in a similar fashion but the others will need to be run differently.
I was trying to use select choice and case and for loop.

1. This is with you code and the menu works.
DYNAMIC_ITEMS="fix_cron fix_ndd fix_serial fix_vftab ipmp.ksh new_bp_conf"
    [ $CHOICE ] && $ECHO $CHOICE


Which produces :
 1) ALL
 3) fix_cron
 4) fix_ndd
 6) fix_serial
 7) fix_vftab
 8) ipmp.ksh
 9) new_bp_conf
10) MENU

The problem is that ALL items are run the same way, in this case $ECHO $CHOICE.

Here is my manual method:
#select CHOICE in Configuration uiss_test fix_cron fix_ndd fix_serial fix_vftab ipmp.ksh new_bp_conf ALL MENU Quit                                                                                                                       #do
#   case $CHOICE in
#   Configuration)  config;;
#   uiss_test)  config;$UISS_SCRIPTS_DIR/uiss_test;;
#   fix_cron)   echo fix_cron;;
#   fix_ndd)    echo fix_ndd;;
#   echo;;
#   fix_serial) echo fix_serial;;
#   fix_vftab)  echo fix_vftab;;
#   ipmp.ksh)   echo ipmp.ksh;;
#   new_bp_conf)    echo new_bp_conf;;
#   ALL)    echo ALL;;
#    MENU)  menu;;
#   Quit)  exit;;
#    *)  $ECHO "\nINVALID CHOICE:\n";;
#  esac

Everything with exception of Configuration, ALL, MENU,and Quit should be dynamically created.
I also can't get your code to work inside of a case statement. Any help would be appriciated!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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

Creating bash script to process a data file based on the menu

Hey, im fairly new to unix and Im trying to make this unix project that would display a menu and do the following. MENU =========================== (p, P) Print users info (a, A) Add new user (s, S) Search user (d, D) Delete user (x,X) Exit Enter your choice: Trying to... (3 Replies)
Discussion started by: ultimaxtrd
3 Replies

3. Shell Programming and Scripting

Need help creating a menu.

Hi Master of masters, Thanks for ur reply. Need ur help for following. Is it possible to create menu for following in linux or a function. > Look in logs > Status > Action > End Action > CONFSUCCESS > Success > Show message as successful > Enter to continue > CONFFAIL > Failure > Show... (1 Reply)
Discussion started by: rajeshwebspere
1 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. Shell Programming and Scripting

Menu in Menu script issue

Problem: I am trying to create a menu in a menu script and I am running into an issue with the calculator portion of the script. I am first presented with the ==Options Menu== which all 5 options working correctly. Now comes the fun part. I select option 1 which takes me to my ==Calculator... (1 Reply)
Discussion started by: iDdraig
1 Replies

6. UNIX for Dummies Questions & Answers

Creating a List of Files With Find

Hi, I need to go through all the files on my system and build a list/output file with the paths of all files where the first two characters within the file match an expression. I know I can use something like find . | xargs cut -b1-2 or find . -exec cut -b1-2 {} \; to get the characters... (3 Replies)
Discussion started by: 008_
3 Replies

7. Shell Programming and Scripting

Creating a menu

Hi, I need your help co create a very small menu somthing that look like this: 1. first step 2. second step 3. last step from step : ___ to step : ___ If the user choose 1 --> it will echo : Hellow If the user choose 2 --> it will echo : World If the user choose 3 --> it will echo... (4 Replies)
Discussion started by: yoavbe
4 Replies

8. Shell Programming and Scripting

Creating a menu within a script file

I am very new to Unix and know the basic commands. I have to write a script file and I'm completely lost. The script file is to show the following at the beginning: Menu of Options 1. Display all files in a user's home directory. 2. Welcome yourself to the program. 3. Display System... (8 Replies)
Discussion started by: sinjin
8 Replies

9. Shell Programming and Scripting

Creating menu list from configuration file

Hi folks, I have the following function ,which generates menu for installation type: select_install_type() { echo echo ======================================== echo Please select the type of installation: echo ======================================== ... (8 Replies)
Discussion started by: nir_s
8 Replies

10. 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