- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- exiting a program
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
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
тАО09-29-2001 11:15 AM
тАО09-29-2001 11:15 AM
I'm writing a shell script that when it exits to log off the user that started it(Posix shell if it matters in this case). There isn't a command to logoff or exit that I could call that I've found.
Thanks in advance,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2001 11:43 AM
тАО09-29-2001 11:43 AM
SolutionIf your script is one that you want to launch when the user logs in, and when it exits, the user is logged off, then their our two easy ways. These methods are well suited with menu-based scripts.
One method is to launch your script as the last command of the user's login profile, as:
# exec $HOME/my.script
The other method is to declare the script as the program to use in lieu of the normal shell in the sixth field of the user's /etc/passwd entry.
In either case, when the script exits, the user will be logged-off.
The advantage to the second method (making the default shell be your script) is that the user cannot escape into a shell from within your script. Remember that simple commands like 'more" have this ability, and you may want to restict that for security reasons.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2001 12:02 PM
тАО09-29-2001 12:02 PM
Re: exiting a program
within your script you can kill the login shell with:
kill -9 `who am i -T|awk '{print $8}'`
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2001 12:07 PM
тАО09-29-2001 12:07 PM
Re: exiting a program
I second Jim's option of defining the user's shell as the script, but if that is not an option, then what you can do is when the user logs in and runs the script, as the last thing do a kill on the PPID which would be the shell which spawns this script. If you are spawning lots of other child processes then i would recommend storing the PPID early on in the script to a variable and then do a kill on that variable as the last thing in the script.
-HTH
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2001 12:40 PM
тАО09-29-2001 12:40 PM
Re: exiting a program
Thanks again!!
(I'll have a crown some day!! LOL)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2001 01:05 PM
тАО09-29-2001 01:05 PM
Re: exiting a program
One last point:
If you want your shell to have the environmental variables of its $HOME/.profile, then the 'exec' mechanism I first suggested would provide that. In addition, if your script wanted to offer the ability to "shell-out", it could. Having done so, the user could execute commands in the subshell and upon exiting the subshell, return to your script.
Regards!
...JRF...