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...
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
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....
What the block of code is: to make sure that the
.profile (or whatever) was started using the dot command, something like this:
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.
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)
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)
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)
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)
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)
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)
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)
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)
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)