cancel
Showing results for 
Search instead for 
Did you mean: 

auto logout

SOLVED
Go to solution
HPquestion
Regular Advisor

auto logout

Hi there,
We are calling an X-windows based application from the .profile via reflection X automatically . Once the user exit out the application , I want to logoff the shell automatically as we don't want them to get the $ prompt at all.

Tried with kill -9 $$ and some thing like
shown below. Buit the $ prompt still remain.How to logout the users automatically after he/she is done with the application?

.profile code to execute the application.


cd /home/somestuff
./run_the_application
./kill_it
--------
kill_it has the following lines

#!/bin/ksh
MYUSER=`whoami`
for MYPID in `ps -ef | grep $MYUSER | awk '{ print $(2) }' | sort -r`
do
`kill -9 $MYPID`
done

46 REPLIES
Steven Schweda
Honored Contributor

Re: auto logout

How about something like this?:

cd /home/somestuff
exec ./run_the_application

"exec" causes "./run_the_application" to
replace the shell, so when it exits, the
process should die.

HP-UX-free example:

ALP $ rsh /user = root sol
Last login: Wed Feb 11 10:04:53 from alp-l.antinode.
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
You have new mail.
sol# pwd
/root
sol# exec pwd
/root

%RSH-S-REMCLOSED, Remote connection closed
ALP $
HPquestion
Regular Advisor

Re: auto logout

Thnaks! It dodn't work.

.profile with exec ./run_the_application
doesn't stopped opening/executing the application from xterm. Then
I have done the following.But its not existing out the $ prompt in the xterm.

.profile :
exec ./call_run

call_run has the following lines.
#!/usr/bin/ksh
exec ./run_the_application


HPquestion
Regular Advisor

Re: auto logout

sorry made some typos.I meant to say


.profile with exec ./run_the_application
stopped opening/executing the application itself from xterm. So I have done the following.But its not existing out the $ prompt in xterm.

.profile :
exec ./call_run

call_run has the following lines.
#!/usr/bin/ksh
exec ./run_the_application
Patrick Wallek
Honored Contributor

Re: auto logout

Just put an 'exit' after the './run_the_application' in the .profile.

When you exit the application, it will proceed to the next statement in the .profile file and exit out.

cd /home/somestuff
./run_the_application
exit
HPquestion
Regular Advisor

Re: auto logout

I tried the the exit earlier. If I put exit in the .profile, it doesn't open the application from Xterm at all.
Patrick Wallek
Honored Contributor

Re: auto logout

What kind of errors are you getting when it doesn't run?

The 'exit' after the 'run_the_application' should have no effect on the command, UNLESS you are doing a './run_the_application &', in which case the exit will kill the application when the shell exits.

Verify you are not trying to run the command in the background.
HPquestion
Regular Advisor

Re: auto logout

no error. It doesn't open the Xterm window at all if I put exit in the .profile
HPquestion
Regular Advisor

Re: auto logout

Thanks Parick. I am not running it in the background. If I put exit in .profile , xterm windown doesn't open at all
Steven Schweda
Honored Contributor

Re: auto logout

> [..] But its not existing out the $ prompt
> in the xterm.

What xterm? I think that you're hiding too
many details. Like who creates an xterm.

If you can provide a sample script which
really does something, then it might be
possible to suggest some changes. With no
information about who creates which process
how, running what, I'm lost.
Patrick Wallek
Honored Contributor

Re: auto logout

What is "./run_the_application"? Is that an executable or is it another script? If it is a script, please post the contents. There may be some code in there that is affecting us.
HPquestion
Regular Advisor

Re: auto logout


We are using reflection X software.

Reflection x is passing

/usr/bin/X11/xterm -fn 6x13 -sb -ls -display %IP#% -name %T% &)

command to open the xterm
HPquestion
Regular Advisor

Re: auto logout

"./run_the_application" is a binary executable.
Patrick Wallek
Honored Contributor
Solution

Re: auto logout

What you should do is put all of this in its own script and call it with the '-e' option to xterm.

Create a small scripts and "run_the_application.sh" and put it somewhere.

The contents would be:

# cat run_the_application.sh
#!/usr/bin/sh
cd /home/somestuff
./run_the_application

Be sure to take the lines out of the .profile, and make sure you make run_the_application.sh executable for the appropriate users.

Now modify your xterm line to be:

/usr/bin/X11/xterm -fn 6x13 -sb -ls -display %IP#% -name %T% -e /path/to/run_the_application.sh &)
HPquestion
Regular Advisor

Re: auto logout

Thanks Patrick...its working now :-)
HPquestion
Regular Advisor

Re: auto logout

It worked..now I have a related question.

usr/bin/X11/xterm -fn 6x13 -sb -ls -display %IP#% -name %T% -e /path/to/run_the_application.sh &)

My unix auditor doesn't like to see startup program as /usr/bin/csh in the /etc/passwd file as these users are not allowed to open a shell and do anyting. They are just allowed to run the application using x windows directly.

But if I put the startup program as /usr/bin/false instead of /usr/bin/csh for these user, the above command doesn't open the desired application.
What to do?

Thanks again!
Bill Hassell
Honored Contributor

Re: auto logout

It sounds like you want just the Xprogram to run and then disappear. Rather than put a real shell for a restricted user, create a shell script that starts your Xprogram followed by exit. Then the user's shell will actually be the script. Most Unix sysadmins do everything they can to prevent the scummy csh from ever running anywhere. Your shell script should look like this:

#!/usr/bin/sh
export DISPLAY+$(who -muR | awk '{print $NF}'):0.0
/full/pth/to/your/Xprogram some-params
exit

Save it and use chmod 755 yourScript. Run it interactively to make sure it works. Note that if any other variables are required for this program to run, be sure to include them in this script.


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: auto logout

>Bill: export DISPLAY+$(who -muR | awk '{print $NF}'):0.0

Slight typo: export DISPLAY=$(who -muR ...
HPquestion
Regular Advisor

Re: auto logout

Tried something like below as suggested. but its not opening the application at all.

#!/usr/bin/sh
export DISPLAY=$(who -muR | awk '{print $NF}'):0.0
/full/pth/to/your/Xprogram some-params
exit


Thanks for any help on this
Bill Hassell
Honored Contributor

Re: auto logout

Tried something like below as suggested. but its not opening the application at all.

#!/usr/bin/sh
export DISPLAY=$(who -muR | awk '{print $NF}'):0.0
/full/pth/to/your/Xprogram some-params
exit

Try something is known to work:

#!/usr/bin/sh
export DISPLAY=$(who -muR | awk '{print $NF}'):0.0
/usr/bin/X11/xclock
exit

This should bring up the Xwindows clock. Your application should follow the $DISPLAY variable but if it does not, set the display according to their documentation.


Bill Hassell, sysadmin
HPquestion
Regular Advisor

Re: auto logout

Thanks for your reply!
Display is not an issue. User can open the xterm session directly.
Application or Xclock only works when I write /usr/bin/ksh.But once I close the clock or application $ prompt open. It defeats the purpose. I don't want to give user ability to get the $ prompt.

#!/usr/bin/ksh
#export DISPLAY=$(who -muR | awk '{print $NF}'):0.0
/usr/bin/X11/xclock
/usr/bin/ksh
exit
Mel Burslan
Honored Contributor

Re: auto logout

I personally have not done this, so take this one as a suggestion not a how to.

Instead of going into this much trouble, closing the shell after the user finishes using the application, let them drop to a restrictive shell where the only command they can run, is the /path/to/run_the_application

the details of how to set this up can be found under

man sh-posix

look under "rsh Restrictions" heading.

Just a suggestion.
________________________________
UNIX because I majored in cryptology...
Bill Hassell
Honored Contributor

Re: auto logout

> #!/usr/bin/ksh
> #export DISPLAY=$(who -muR | awk '{print $NF}'):0.0
> /usr/bin/X11/xclock
> /usr/bin/ksh
> exit

I'm not sure what you are doing. You need to create a simple file with 4 lines in it like this:

#!/usr/bin/ksh
export DISPLAY=$(who -muR | awk '{print $NF}'):0.0
/your/program
exit

Don't add any other lines. Save this file in a common location such as /usr/local/bin/myprog and set the permissions to 755 with:

chmod 755 /usr/local/bin/myprog

Now, login using telnet or ssh, then type this command and logout:

chsh $LOGNAME /usr/local/bin/myprog
exit

Now login again and your program should start. Close the program and the telnet or ssh window will also close. NOTE: If your program requires environment values, be sure to put them into this little script.


Bill Hassell, sysadmin
Hakki Aydin Ucar
Honored Contributor

Re: auto logout

> Bill :

>>
#!/usr/bin/ksh
export DISPLAY=$(who -muR | awk '{print $NF}'):0.0
/your/program
exit
>>

just about to add somethings to your code; for some reasons ,sometimes unable to get hostname (in some custoemr servers) ,so the following needs:

#!/bin/sh

export DISPLAY=`hostname`:`who -muR | awk '{print $NF}' | cut -d ':' -f 2`
echo $DISPLAY



HPquestion
Regular Advisor

Re: auto logout

Bill,

The script itself working fine if you logon to a shell and execute it. There is nothing wrong in the DISPLAY variable or any permission. All I wanted to do is that calling that script directly as a user startup program (instead of shell like /usr/bin/ksh) so that user wonl't get the shell prompt at all. If I call the script as startup program ( which is visible in /etc/passwd) for a user , its not working at all.

#!/usr/bin/ksh
export DISPLAY=$(who -muR | awk '{print $NF}'):0.0
/your/program
exit


Thanks for all your help on this!