Operating System - HP-UX
1820733 Members
3299 Online
109627 Solutions
New Discussion юеВ

Re: Control-c to logout from from .profile

 
SOLVED
Go to solution
Visweswara R Madhavarap
Occasional Contributor

Control-c to logout from from .profile

How can I add the line in .profile file "To logout while press on control-c ". I used trap command but it was exit from shell not to the Server.

Can anyone help me, how to reslove this.


Thanks
9 REPLIES 9
Geoff Wild
Honored Contributor

Re: Control-c to logout from from .profile

Control C is break on the OS.

Use Control d to logout.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Calandrello
Trusted Contributor

Re: Control-c to logout from from .profile

firend
ctrl + D
spex
Honored Contributor

Re: Control-c to logout from from .profile

Hi,

The eof control character determines which keystroke will result in a logout. The default setting is ^D (control-D), but this can be changed via 'stty eof '. The change can be made permanent by modifying the appropriate line in ~user/.profile or /etc/profile. In other words, find a similar line to this in ~user/.profile:

stty erase "^H" kill "^U" intr "^C" eof "^D"

and change "^D" to "". Note that you will be changing standard UNIX behavior by doing this.

PCS
jerry1
Super Advisor

Re: Control-c to logout from from .profile

In .profile put:

trap exit 2


You have to logout and login for it to
work. sourcing ". ./.profile" from command
line is not enough.
Or if your using .kshrc with .profile
just put it in .kshrc and source .kshrc.
Then it will work also.

Both will only work with the first evoked login shell and other sh shells evoked within the current shell but not any ksh
shells evoked within the current shell. ??
Visweswara R Madhavarap
Occasional Contributor

Re: Control-c to logout from from .profile


Thanks for responses.


I have Tried all those options which didn't work.

Here is the requirement; I am executing one script thru .profile. As soon as user logs in that menu script will execute he can choose the option based on his requirement, if user press Ctrl-C he will go to his home directory but our intension is user should not go to home directory


Tahnks
Ivan Krastev
Honored Contributor

Re: Control-c to logout from from .profile

Try in your script:

trap '' 2

or

trap 'echo "Control-C disabled."' 2

regards,
ivan
James R. Ferguson
Acclaimed Contributor

Re: Control-c to logout from from .profile

Hi:

As I understnad your question, you are executing only one script in your user's profile and you want to completely log off the user when the script finishes.

If that is the case, one way is to 'exec' your script at the end of the profile:

...
exec /home/user/menu.sh

In '/home/user/menu.sh' add a trap that looks like:

trap '' INT QUIT

Regards!

...JRF...
Matti_Kurkela
Honored Contributor
Solution

Re: Control-c to logout from from .profile

Ah, so you want to make it impossible for the user to "escape" to the shell from the menu system. Right?

You should make a script that is equivalent to the current .profile of the menu script user(s). Place that script in some location that is accessible to all menu script users but not modifiable by them. Normally /usr/local/bin might be a good place.
(For example, the script might be named as /usr/local/bin/loginmenu)

Then you must make it so that the menu script can be used as a valid login shell. You must add the name of this script into /etc/shells file; if that file does not exist, create it and add the names of the standard system shells plus the name of your menu script:
/sbin/sh
/usr/bin/sh
/usr/bin/rsh
/usr/bin/ksh
/usr/bin/rksh
/usr/bin/csh
/usr/bin/keysh
/usr/local/bin/loginmenu

(This list of standard shells is copied from "man getusershell". It is the default list which is used if /etc/shells does not exist. If you create /etc/shells but forget to include the standard shells, you may lose the ability to log in.)

The last step is to change the menu script users' login shell to /usr/local/bin/loginmenu. This can be done using the command:
usermod -s /usr/local/bin/loginmenu someuser
or
chsh someuser /usr/local/bin/loginmenu

After this, the user's session ends if the loginmenu script stops executing for any reason.
MK
Visweswara R Madhavarap
Occasional Contributor

Re: Control-c to logout from from .profile

Thanks for your response. I have added the following line my .profile file.

trap 'menu.sh' INT