The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script to manipulate a message count for the same IP @ diff session gobinath Shell Programming and Scripting 1 05-28-2008 03:13 PM
tcsh + completing a sub-directory entry JamesGoh Shell Programming and Scripting 0 04-23-2008 03:52 AM
Running a script without a terminal session jjinno Shell Programming and Scripting 3 10-03-2007 01:50 AM
Completing ffmpeg installation noamon UNIX for Dummies Questions & Answers 1 01-29-2007 11:14 AM
sqlplus session being able to see unix variables session within a script 435 Gavea Shell Programming and Scripting 2 07-03-2006 10:11 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-07-2004
deepsteptom deepsteptom is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 3
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
  #2 (permalink)  
Old 06-07-2004
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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
Code:
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.
  #3 (permalink)  
Old 06-08-2004
deepsteptom deepsteptom is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 3
Reply to Jim : Termination of Session

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
  #4 (permalink)  
Old 06-08-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
I merged the threads. This thread was not closed. Why could you not reply to it?
  #5 (permalink)  
Old 06-08-2004
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
What the block of code is: to make sure that the
.profile (or whatever) was started using the dot command, something like this:
Code:
.  .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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0