Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading from a Menu

Status
Not open for further replies.

troyarch

MIS
Mar 12, 2003
29
0
0
US
I would like to have a kornshell script automatically read from a menu and enter a response at the command line. I already know the menu options and what my responses will be. I just need to automatically interact with the menu. Any help would be much appreciated.

If there is an easier way to read from a menu with a perl script I can do that as well.

An example of the menu is below.


1: Checkout Clearcase LABEL for Application was.

2: Deploy Application was to the WebSphere Environment.

3: STOP WebSphere Application Server for was application on the test123 node.

4: STOP WebSphere Application Server for was application on the test234 node.

5: START WebSphere Application Server for was application on the test123 node.

6: START WebSphere Application Server for was application on the test234node.

7:Bounce WebSphere Cluster for was application.

8: Clear JSP Cache

9: Exit the menu.

Please enter your choice [1,2,3,4,5,6,7,8 or 9]:


 
And what have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Wouldn't it be easier to find out what commands are behind the menu run them relying on exit codes?

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
So far I have tried the read command but I realized that it is meant to be used to read data entered by the user, not the menu. I need to be able to read the menu options so I do not think this will work.

I also tried a funtion (below) that reads if one character is entered--but this technique is also used when the user enters data, not the menu. This function was given in thread 1125925.

function getchar {
typeset OLDSTTY=$(stty -g 2>/dev/null)
stty -icanon -echo min 1 time 0 2>/dev/null
typeset CAR=$(dd bs=1 count=1 <&0 2>/dev/null)
stty $OLDSTTY 2>/dev/null
print $CAR
}

I am not sure which method, if any of these, to keep at. Thanks for helping.
 
I agree that running the code behind the menu options would be easier, but if that code changes then I would have to change my code also. I do not administer the code that runs menu so I would rather not do this.
 
Since you already know what options you want, can't you use a 'here doc'?

For example:

Code:
menu_prog <<EOF
1 (...or Whatever option you need)
EOF

Regards,
Chuck
 
I'm not exactly sure how the here document would work in this scenario but I'll look into it. Thanks everyone!
 
It looks like the select comand is to create a menu--I want to interact with an existing menu.
 
Depending on how the menu program was written, you might try and create a text file containing line per line the menu options you want the menu program to perform:

/tmp/menu-options-to-perform
-----------------------------
1
4
8
9
---------end-of-file---------

then run the menu program like so
/path/to/menu-program </tmp/menu-options-to-perform

You can also try that same thing with a here-document (saves you creating a temp file)

/path/to/menu-program <<eof_menu
1
4
8
9
eof_menu

If that doesn't work, it may be due to the fact that your menu program will only read input from the keyboard, if so, you'll have to find out about "expect", which is a way to run interactive programs in a non-interactive way.




HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top