Terminate session on completing script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Terminate session on completing script
# 1  
Old 06-07-2004
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  
Old 06-07-2004
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  
Old 06-08-2004
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  
Old 06-08-2004
I merged the threads. This thread was not closed. Why could you not reply to it?
# 5  
Old 06-08-2004
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Terminate shell script after a specified time

I have a shell script that checks a file state.txt, deletes fit.bin if state.txt is empty. I cron this at 2am, I will want the script to stop by 8am irrespective of the value of state.txt, any ideas? #!/usr/bin/ksh while true; do if ] ; then echo else rm ~/fit.bin exit ... (8 Replies)
Discussion started by: aydj
8 Replies

2. Shell Programming and Scripting

Run script every minute and terminate after specified number of executions

when it runs and look at my acron.log file it generates an error as below /tmp/prog.sh: line 4: (12 Replies)
Discussion started by: azherkn3
12 Replies

3. Shell Programming and Scripting

Need help with completing a bash script

Hello All, I am automating a task using bash script and got stuck at this. From the below input, Meta Device Members (20) : { ---------------------------------------------------------------------- BCV DATA RDF DATA ... (7 Replies)
Discussion started by: Sam R
7 Replies

4. Shell Programming and Scripting

Looping not completing in shell script

Hi, Iam using below code to login to servers to get cpu utilisation. but output is coming for only one server. code is below root@blr-svr-oclan-01 # more SSSC_CPU_UTIL1.sh #!/bin/sh echo "CPU UTILIZATION" while read line; do IDLE=`/usr/local/bin/sshpass -p 'xxx' ssh xxx@$line 'sar 2 2' |... (1 Reply)
Discussion started by: surender reddy
1 Replies

5. Shell Programming and Scripting

Terminate a process using shell script

Hi, I am writing a shell script to run a process and write the output of the process to a file. Inside program.sh: ./process.sh > tempfile .. open tempfile do the following But the problem is that process.sh is running indefinitely and program.sh is not executed completely. Can... (4 Replies)
Discussion started by: dreamgirl314
4 Replies

6. Shell Programming and Scripting

strange behaviour script terminate before complete execution

I'm working on a script to make backup of various folder located on various host using different OS. I got a strange behaviour because the script donět process all lines of a configuration file, the script execute only one loop even the input file have 6 lines: This is the script: #!/bin/bash... (4 Replies)
Discussion started by: |UVI|
4 Replies

7. Shell Programming and Scripting

how to terminate ssh connection without terminating script

Hi all, I connect with SSH connection to remote machine in the script and ı want to logout at half of the script then continue to script. If ı write exit in the script it terminates script not SSH connection. How can i do that please help me (1 Reply)
Discussion started by: fozay
1 Replies

8. Shell Programming and Scripting

shell script exiting before completing

I have a script which has the following statement, /opt/oracle/product/9i/bin/sqlplus << EOC >> $LOG_FILE 2>&1 username/password ---- Enters the SQL prompt @/export/home/oracle/shells/grant_userview.sql ---Runs the SQL script @/export/home/oracle/shells/grant_proc_userview.sql ---Runs the... (6 Replies)
Discussion started by: welldone
6 Replies

9. Solaris

I am not able to login in gnome session and java session in Sun solaris 9& 10

I am not able to login in gnome session and java session in Sun solaris 9& 10 respectively through xmanager as a nis user, I am able to login in common desktop , but gnome session its not allowing , when I have given login credentials, its coming back to login screen, what shoul I do to allow nis... (0 Replies)
Discussion started by: durgaprasadr13
0 Replies

10. Shell Programming and Scripting

sqlplus session being able to see unix variables session within a script

Hi there. How do I make the DB connection see the parameter variables passed to the unix script ? The code snippet below isn't working properly. sqlplus << EOF user1@db1/pass1 BEGIN PACKAGE1.perform_updates($1,$2,$3); END; EOF Thanks in advance, Abrahao. (2 Replies)
Discussion started by: 435 Gavea
2 Replies
Login or Register to Ask a Question