Operating System - HP-UX
1833861 Members
2262 Online
110063 Solutions
New Discussion

Re: disable control c on shell user program.

 
SOLVED
Go to solution
Juan Manuel López
Valued Contributor

disable control c on shell user program.

Hi all.
I have a user which shell is sh.
On his .profile there is a line calling to an shell script which is a menu, once the user is running that script, I don??t want he can make control-c to stop the script and go out to sh shell.
What is the way to do this ?.

Thanks.

Juanma.
I would like to be lie on a beautiful beach spending my life doing nothing, so someboby has to make this job.
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: disable control c on shell user program.

Hi:

Add this to your shell:

trap '' int

...or if you wish to offer a message with receipt of the CNTL_C:

trap 'echo control_C has been disabled' INT

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: disable control c on shell user program.

Plan A.

trap '' 2

Plan B.

Alter intr to an impossible value, e.g. Octal 377

stty intr '\377'
If it ain't broke, I can fix that.
John Dvorchak
Honored Contributor

Re: disable control c on shell user program.

I don't know if this will help or not. But years ago I used to have users like that and I simply put "exit" as the last line in the .profile file. Something like this:

#start of .profile
.
.
.
.
#call the menu
/usr/bin/your_menu
exit

End of .profile

When your_menu is terminated, either on purpose or by any key stroke, the next command in .profile is an exit and it forces the user back to a logon screen.

Good luck.
If it has wheels or a skirt, you can't afford it.
Jose Mosquera
Honored Contributor

Re: disable control c on shell user program.

Hi,

Other possible way is the following:

#Start of menu script
stty intr ''
.
.
.
.
stty intr '^C' #Restore Ctrl-C feature
#End of menu script

Rgds.
Juan Manuel López
Valued Contributor

Re: disable control c on shell user program.

Thanks to everyone for your help.
Special Thanks to Clay, Your plan B works fine.
Thanks again.

Juanma.
I would like to be lie on a beautiful beach spending my life doing nothing, so someboby has to make this job.
Kevin Tuitt
Occasional Advisor

Re: disable control c on shell user program.

have you tested the above trap(s) against CTRL \?

You may find a better way is to run the menu as the users shell. Ensure that you reference the .profile and /etc/profile from within the menu (shell) and include the menu (shell) in /etc/shells if this file exists on your system.

When the login menu (shell) exits, there is nowhere else for the user to go.
When you are right, no-one remembers; When you are wrong, no-one forgets.