Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exiting via a script

Status
Not open for further replies.

A5k

Programmer
Jul 29, 2001
54
CA
Hi all,
I'm trying to write a script that, when completed will log the user out of their account. Any helpful hints ideas?

pseudo script
ls -al
chmod 700 *
exit


It's the "exit" that I can get. I have to somehow exit the parent from a child...hrmmmm

-a5k
 
One way is to exec the script from the user's .profile.

But this won't allow them to do anything other than run that script ...
 
One way I've discovered is using the ". command". Let's say the name of the script is bye, then the command would look like:

$. bye

The dot command executes the script in the current shell without spawning a child process. Still not exactly what I'm looking for....

-a5k
 
Try the following...

1) First, place the following line in your [tt].profile[/tt] (assuming Korn shell here)...
[tt]
export ROOTPID=$$
[/tt]
This is to capture the process id of the top level process in the session.

2) Then, in your script where you want to log them out...
[tt]
sync ; sync ; sleep 1
kill -HUP ${ROOTPID}
sleep 3
kill -9 ${ROOTPID}
[/tt]
The first two lines, the sync's, sleep, and first kill, are to try to let the session end nicely, flushing buffers and cleaning up before it dies. The final "kill -9" is the icepick in the forehead kill that terminates the session.

There may be an easier way, this is just what came to mind first.
 
1. ------

should work if PseudoScript is a child of the logon shell

Create alias, define in .profile

alias PseudoScript='. PseudoScript"

where PseudoScript

echo 'Hello, GoodBye'
exit


2. ------
Should work for nested shells IF login and logout command user match

where PseudoScript

echo 'Hello, GoodBye'
logout


JRjr [morning]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top