LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   logout after script runs (https://www.linuxquestions.org/questions/linux-newbie-8/logout-after-script-runs-336500/)

bigdog0007 06-23-2005 03:00 PM

logout after script runs
 
I wrote a menu script ... that launches automatically when a certain user logs in ... now i am trying to make it log the user out when they choose the Exit option... if i use the 'exit' command it just goes to the prompt... if I use the 'logout' command it gives me an error "not login shell: use 'exit'

What command do you use in a script to log the user out of the system without them going to the prompt???

Thanks, The :newbie:

rjlee 06-23-2005 03:18 PM

You can't do that like that. Basically, any given process cannot tell any other process to exit unless the other process explicitly lets it. This is done to encourage good design as well as as a security measure.

What you probably want to do here is to make the login script be the menu script that you're using; you can set this in /etc/passwd (it's the last field on the line).

Alternatively, you could modify the BASH script that calls your menu script to exit if it receives a given exit code.

bigdog0007 06-23-2005 03:23 PM

I think I figured it out for myself ... instead of loging out at the end of the script... i use the exit command at the end of the .bash_profile for that user... the only thing I need to figure out now is:

How to keep them from [BREAK]ing (Ctrl + C) the program... or force a logout if they do.... any takers :p

bigdog0007 06-23-2005 03:27 PM

Thanks RJLee... I didn't see your post when responded to mine :p ... Would changing the passwd file to point to my file stop them from [BREAK]ing the script and going to the prompt?

rjlee 06-23-2005 03:38 PM

Yes, because there wouldn't be a prompt for them to go to. Breaking would exit the script, causing the user to logout.

I don't know what would happen with ctrl+y and ctrl+z though. This normally suspends a job for continued execution later; I think this is implemented by BASH though, so there shouldn't be a problem if you don't have a login shell. Still, there's no harm in trying it.

bigdog0007 06-23-2005 04:04 PM

Wow... that is great.... the (Ctrl + C) accually caused it to lock that session ... thats fine with me ... the other 2 didn't seem to have any effect at all... and when the exit option is use it logs out ... just what the doctor ordered :D


THANKS!!!!

rjlee 06-24-2005 06:42 PM

Quote:

Originally posted by bigdog0007
Wow... that is great.... the (Ctrl + C) accually caused it to lock that session ... thats fine with me ... the other 2 didn't seem to have any effect at all... and when the exit option is use it logs out ... just what the doctor ordered :D


THANKS!!!!

If you want to stop it from locking, then you probably want to look at installing a handler for the SIGTERM signal. In bash, you can do this with the trap command; in Perl you can use $SIG{TERM} = sub {}


All times are GMT -5. The time now is 02:31 AM.