- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Is it possible to prevent the user using a CTRL-C ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-21-2007 01:21 AM
тАО01-21-2007 01:21 AM
Is it possible to prevent the user using a CTRL-C combination
I have a .profile that call another ( main menu ) and I need to prevent user using a CTRL-C combination to break the process and stop in a OS prompt. I have to force them that when they leave the called script ( main menu ) the process terminated with exit and close their unix session.
When the users use CTRL-C in the called script it may be that the previous process receive the CTRL signal and the users stay in a OS prompt without closing the Unix session. It's disastrous if they use the command line.
I hope I'm clear enought to you understand my problem.
Thanks
Jose Castro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-21-2007 03:48 AM
тАО01-21-2007 03:48 AM
Re: Is it possible to prevent the user using a CTRL-C combination
Instead, use the "usermod" or "chsh" commands to change the user's default shell to be the menu script.
After this change, if the user interrupts the menu script, the session is automatically terminated.
You may have to create/modify the /etc/shells file to allow the modified user to log in with the custom shell. If the file does not exist, list all the standard shells in that file too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-21-2007 04:18 AM
тАО01-21-2007 04:18 AM
Re: Is it possible to prevent the user using a CTRL-C combination
trap '' 2
or
trap 'echo "Control-C disabled."' 2
regards,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-21-2007 05:03 AM
тАО01-21-2007 05:03 AM
Re: Is it possible to prevent the user using a CTRL-C combination
Use signal trapping before invoking sequences in your script.
If you are only particular about CTRL C (SIGINT)you can use
trap " " 2
for silently ignoring the interrupt in the fore ground.
If you want to dispaly any message use
trap "echo YOUR MESSAGE" 2
You can refer the file at /usr/include/sys/signals.h file to see more UNIX signals (need to scroll down a bit it is under /* Signal numbers */), which you may be intersted to use within your script to avoid any kind of break in your script execution.
Happy Scripting.
TQ
Perumal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-21-2007 05:54 AM
тАО01-21-2007 05:54 AM
Re: Is it possible to prevent the user using a CTRL-C combination
trap "" 1 2 3
and at the bottome:
trap 1 2 3
Now this looks a bit strange but here's what is happening:
The first trap says:
> When signals 1, 2 or 3 are sensed by the program, do the following: "" (which is do nothing)
and the second trap says:
> Return signals 1, 2 and 3 to their normal behavior.
Signals:
1=hangup (loss of connection has occurred)
2=interrupt (CTRL-C for interactive users)
3=quit (causes a program to core dump)
AS memtioned, you don't want a normal shell that starts your menu. Instead, change the shell from /usr/bin/sh to /usr/contrib/bin/menu_script and put only the required profile items plus the traps into the menu program. In your case, just use trap "" 2 at the start of your menu script.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-21-2007 08:41 PM
тАО01-21-2007 08:41 PM
Re: Is it possible to prevent the user using a CTRL-C combination
In the previous posts you have got a description for how to trap the Ctrl+C signal.
#! /usr/bin/sh
# POSIX shell script
# Script name: menu.sh
# Disable Ctrl+C and interrupts
trap 'echo "\aProgram is terminated";rm $TMPFILE;exit' 1
#....your menu script...
Note line 1. You should always specify what kin of shell you are running.
Note 2: As you can see you can run multiple commands in the trap before leaving.
Note 3: If you have written the menu in csh you should use "onintr CTRLC" instead of trap.
#!/usr/bin/csh
onintr CTRLC
LOOP:
echo 'Continue Until
read DUMMY
goto LOOP
CTRLC:
echo "You pressed Ctrl+C"
exit
Secondly, I would propose that you edit the /etc/shells and add this "menu" to the allowed shells and then use it as login script (this file should contain all shells you use as login shells)
#cat /etc/shells
/sbin/sh
/bin/sh
/bin/ksh
/bin/csh
/usr/bin/ksh
/usr/bin/sh
/usr/bin/csh
/usr/bin/false
/usr/bin/ftpshell
/usr/local/bin/menu.sh
When the user exit the menu they will logout.
/Tor-Arne
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2007 12:22 AM
тАО01-22-2007 12:22 AM
Re: Is it possible to prevent the user using a CTRL-C combination
Call the menu from ~user/.profile with the 'exec' command. The session will immediately after the menu's process terminates.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2007 04:39 AM
тАО01-22-2007 04:39 AM
Re: Is it possible to prevent the user using a CTRL-C combination
From your question, you seem to want to prevent a user from running an arbitrary command. Most Shells weren't designed to be run on behalf of a non-trusted user. You may want to reconsider writing your menu in shell, and rather use a "c" program, to better control your inputs.
Shells respond not only to signals, as you noticed, but depending on the type of input you bring in... they respond to field separators escape-sequences, and quoting, that could, in some cases, lead to arbitrary command execution.
-Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2007 09:17 AM
тАО01-22-2007 09:17 AM
Re: Is it possible to prevent the user using a CTRL-C combination
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2007 10:21 AM
тАО01-22-2007 10:21 AM
Re: Is it possible to prevent the user using a CTRL-C combination
Please check back with the 'best' solution for you and award points ackordingly
http://forums1.itrc.hp.com/service/forums/helptips.do?#28
Regards,
Hein (0 points for this)