Visit Our UNIX and Linux User Community


Use of stty vs trap in script-driven login menu


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of stty vs trap in script-driven login menu
# 1  
Old 03-14-2012
Use of stty vs trap in script-driven login menu

My employers would like me to selectively run one of several different (already-existing) Korn Shell menu-driven scripts out of the user's .profile file, depending on some yet-to-be-specified user critieria.

I've never done this kind of thing, but I have the existing scripts (among other things) to look at.

One of the classic concerns when writing such a login menu is the user's ability or inability to break out of it. I'd read that this is where the shell "trap" command is used to trap signals that would normally break out of the script. But the existing scripts don't do that. Instead I see lines like:

stty susp <undef>
stty quit <undef>

and so forth. This undefines the key sequences for interrupt, suspend, etc.

It seems to me that maybe this is a better approach than the 'trap' command, because it does not disrupt the default (and presumably better-thought-out) handling of signals caused by things other than the user pressing keys.

Does anyone have any experiences/opinions about this? Which is the better approach?

Also, what are the advantages/disadvantages/dangers of actually replacing the user's login shell in the password file with the menu script?

Finally, is there any such thing as a generalized (and presumably compiled) menu shell that takes text files of choices and actions as inputs? I could not find any such thing in via Google.
# 2  
Old 03-14-2012
You are asking several questions

1. you can compile a shell script using the shc tool, you have to compile the tool on your machine.
Francisco Rosales, home page

2. DO NOT make the users shell the shell script

3. One of the best approaches is to chroot the user. Create a chroot jail. The only downside is that you have to have copies of ALL the shells, commands the shell scripts call, and any special application code etc., - inside the jail. One copy for everybody is fine. Even if the use gets "out" of the menu somehow, he/she cannot do much.

This gives an overview and some howto. If you want to try it there are dozens of tutorials on the net. google for 'chroot howto'

Best Practices for UNIX chroot() Operations

4. another choice is to use a restricted shell - usually /bin/rsh as the login shell, check your documentation.
Run the menu under that shell. Again it may or may not be a choice, but check it out anyway.

On purpose, I kinda ignored the signal trapping. When you set things up well to start with, signal trapping is a lesser concern.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 03-14-2012
In addition to disabling certain keys with "stty" one basic precaution is to "exec" the menu script as the last line of the user's login profile thus reducing the chance of being dropped to a shell prompt.
This User Gave Thanks to methyl For This Post:
# 4  
Old 03-14-2012
I'd consider trap safer because it can eat a SIGINT from any source -- kill and the like -- not just those that come from the keyboard. Besides, who's to say you don't want the program to do something on ctrl-c?

The main advantage of changing their login shell to your script is that, if they manage to kill it somehow, all they accomplish is logging themselves out. There's no interactive shell behind your application to "break out" into. Disadvantage is that it can be harder to arrange. Some systems need you to add your application to /etc/shells before they'll let people use it as their 'shell'.

I'm sure there's general-purpose menu systems. Of course, just because something's compiled doesn't mean it doesn't have holes -- it just makes it harder to know whether it has holes...
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 03-14-2012
Quote:
Originally Posted by jim mcnamara
2. DO NOT make the users shell the shell script
Any particular reason?
# 6  
Old 03-15-2012
Hi Guys,
Thanks for the replies and advice.

I thought about chroot, I may try that. As they so often are, the requirements for this task are very nebulous, but I get a sense that part of what I am doing is protecting DBA's from each other, so moving them all into the same chroot'ed envionment may not be a good idea.

The environment is AIX, and I understand that AIX has something alot like Solaris Zones, called logical partions or LPARs. Maybe I should look at that, if they are like Zones then I can give everybody read-only access to one set of executables w/o using any more storage.

I too am interested in specifically why replacing the user's login shell is a bad idea, beyond the obvious objections like I could write a crappy script, etc.

Previous Thread | Next Thread
Test Your Knowledge in Computers #326
Difficulty: Medium
Time on Computers is commonly referred to as GNU Time.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using menu driven script

Hi Team , I wrote a shell script for adding and subtracting two numbers am getting error could some one please help to fix it script: echo "Enter 1 to add:" echo "Enter 2 to sub:" echo "Enter 3 for both addition and subtraction :" read ans; case "$ans" in 1)... (4 Replies)
Discussion started by: knz
4 Replies

2. Shell Programming and Scripting

Menu Driven Bash Shell Script with Default Option

Hi All, I have written a menu driven bash shell script. Current Output is as below: ------------------------------------- Main Menu ------------------------------------- Option 1 Option 2 Option 3 Option 4 Exit ===================================== Enter your... (3 Replies)
Discussion started by: kiran_j
3 Replies

3. Shell Programming and Scripting

Execution Problem with dispalying file content using menu driven script

HI All.. below is my menu options script. in option 2,3 and 4 im giving input and they are saving into their respective text file. problem is when im trying to "cat" those files in options 7,8 and 9 im not getting the output. no respective file contents are displaying on screen. but if i... (1 Reply)
Discussion started by: saichand1985
1 Replies

4. Shell Programming and Scripting

Menu driven script.

I'm a beginner at scripting and have been putting this script together over the past week. It's no where as polish as it could be. Any tips/suggestions on improving this script would be appreciate it. Every week, my team develops WAR files in tomcat on our test environment and moves them to our... (4 Replies)
Discussion started by: bouncer
4 Replies

5. Shell Programming and Scripting

Help needed in writing a menu driven script

Hi, I was wondering if someone could help me write a shell script in Linux that backsup/restores data to anywhere I choose but it needs to be menu driven? Thanks, I'm new to Linux/Unix but liking it so far...just hoping to get to grips with the scripts! :) (7 Replies)
Discussion started by: Nicole
7 Replies

6. UNIX for Dummies Questions & Answers

What is a menu or command line option driven script?

i'm confused what this means. i was asked to design a menu or command line option driven script that reads out of a DB and displays info such as read_data.pl -u <user> -e <event> which would print commands run by <user>with the <event> in the db. any suggestions? i've been using... (2 Replies)
Discussion started by: kpddong
2 Replies

7. SuSE

Write shell script using menu-driven approach to show various system

QUESTION: Write shell script using menu-driven approach to show various system configuration like 1) Currently logged user and his logname 2) Your current shell 3) Your home directory 4) Your current path setting 5) Your current working directory 6) Show Currently logged number of... (1 Reply)
Discussion started by: bboyjervis
1 Replies

8. Shell Programming and Scripting

Menu driven Script needed ..pls help

Hi Guys.. am new to unix scrpiting..I need a Menu need to create using shell scrpting eg: Food items ready paid if i press "f" need to add items for a file food items.. if i press "r" it need to move into ready and remove from food items if i press "p" need to update a filed in... (1 Reply)
Discussion started by: sasdua
1 Replies

9. Shell Programming and Scripting

Assigning values to reference variables for a dynamic menu driven script.

How do I assign values to reference variables? I am assigning a variable name to --> $user_var Then I am trying to change its underlying variable value by $((user_var))=$user_value .. its failing,, Please let me know if there is a way to do this dynamically.. FileA.props... (5 Replies)
Discussion started by: kchinnam
5 Replies

10. Homework & Coursework Questions

Menu Driven Shell Script which accepts1 to 5 options

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) Write a Menu Driven Shell Script which accepts1 to 5 options and performs the following actions for... (1 Reply)
Discussion started by: vaghya
1 Replies

Featured Tech Videos