Terminate session on completing script

Hai all..

How do i terminate my telnet session automatically when my java applicatiion exits. i have a file run which executes my java application and takes care of all class and library path settings prior to the execution. I would like to terminate my session when my application exits. The exit command only takes me out of the scripting session. I want my telnet session to be killed (like what happens when i key in "exit" at the prompt). How do i do this. Aim is that the users who would be running this application through their handheld terminals should never have access to the unix prompt...

Thanks in advance
Deepu

The only way to do this would be to kill the parent pid of the java process from within the java code. And you still would not be guaranteed that the user did not get to the unix prompt.

Try:
Unless you control the whole user environment, it may still be possible to get to the shell. Prolly your best bet is to create a captive user that logs in to a restricted shell, executes some type of .profile or .login script that ends with an "exit" to logout the process. trap as many signals as needed in that script.
Make sure the .login or .profile is sourced.

Here is a basic start

trap "exit" 0 1 2 3  # whatever you need here
# my .profile file for rksh
# check for sourcing and exit if not
Prog=".profile"
if [ $(basename $0) = $Prog ]; then
   kill -9 $PPID
   exit 1
fi
export PATH=".:/usr/bin"  # whatever.....
/path/to/my/javascript
exit 0

This is not bulletproof, even that good, but it's a start.

Note: This is not a new thread. This is a continuation to my earlier post since i was not able to post this message as a reply. Sorry for any inconvenience....

Dear Jim

Thanks for the solution. Its working for me indeed. I added the trap statement and the "exit 0" statement to my .profile. This seems to cut off the user from the unix prompt. Withing the application, all interrupts are handled thereby making sure that the user is not able to generate an interrupt and exit. Application always exits gracefully with an exit status of 3. I omitted the following lines from the sample script that you gave

# check for sourcing and exit if not
Prog=".profile"
if [ $(basename $0) = $Prog ]; then
kill -9 $PPID
exit 1
fi

Could you please explain to me what these lines does...

Also you mentioned that this approach is not bulletproof.. Since it seems to be working fine for me now, i would like to know of situations where this approach fails....

Thanks and regards
Deepu

I merged the threads. This thread was not closed. Why could you not reply to it?

What the block of code is: to make sure that the
.profile (or whatever) was started using the dot command, something like this:

.  .profile

This means the code is being used correctly, not by a regular shell user. Your requirement.

It's pretty hard to make something completely hack-proof. Example: periodically somebody discovers something like a buffer overflow in some call or another, which allows a user to enter kernel mode. They exploit it.

If this is something regular users, ie., friendly users, are going to use it's probably okay. But if it's on a box sitting out outside a firewall, then the story is different.