[comp.unix.wizards] .logout for ksh?

fst@mcgp1.UUCP (Skip Tavakkolian) (10/01/88)

Is there a way to execute something on exit, in Korn shell?
This would be like the ``csh'' ``.logout'' file.

Many thanks.
-- 
Fariborz ``Skip'' Tavakkolian
UUCP	...!uw-beaver!tikal!mcgp1!fst

UNIX is a registered trademark of AT&T

ekrell@hector.UUCP (Eduardo Krell) (10/02/88)

In article <1594@mcgp1.UUCP> fst@mcgp1.UUCP (Skip Tavakkolian) writes:
>Is there a way to execute something on exit, in Korn shell?
>This would be like the ``csh'' ``.logout'' file.

If you RTFM (or buy the book, that just came out) you'll see that
"trap command 0" will do it.
    
Eduardo Krell                   AT&T Bell Laboratories, Murray Hill, NJ

UUCP: {att,decvax,ucbvax}!ulysses!ekrell  Internet: ekrell@ulysses.att.com

artp@motbos.UUCP (Art Parmet) (10/03/88)

In article <1594@mcgp1.UUCP>, fst@mcgp1.UUCP (Skip Tavakkolian) writes:
> Is there a way to execute something on exit, in Korn shell?
> This would be like the ``csh'' ``.logout'' file.

In your /etc/profile file add the following entry:

# run special program at logoff time
trap "/local/bin/logoff" 0

The file /local/bin/logoff (or whatever you choose to run) will be run when the
parent shell of the user sesion dies.

Regards,
Art
-------------------------------- 

<< Unusual Disclaimer >>

Art Parmet - Northeast Area Eng Mgr @ Motorola Semiconductor, Woburn, Ma.
UUCP: {hplabs!motsj1, gatech!mcdchg, arla!oakhill, apps!oakhill}....!motbos!artp

Voice:      +1 617-932-9700     
DID:        +1 617-932-6049
UUCP:       +1 617-932-9191 
Fax:        +1 617-932-9100
POST:          RSXH20

gwyn@smoke.ARPA (Doug Gwyn ) (10/03/88)

In article <1594@mcgp1.UUCP> fst@mcgp1.UUCP (Skip Tavakkolian) writes:
>Is there a way to execute something on exit, in Korn shell?
>This would be like the ``csh'' ``.logout'' file.

The following should work with any Bourne-compatible shell.
In your .profile, add:
	if [ -r $HOME/.logout ]
	then	trap ". $HOME/.logout" 0
	else	trap "exec echo 'logged out'" 0
	fi

wnp@dcs.UUCP (Wolf N. Paul) (10/03/88)

In article <1594@mcgp1.UUCP> fst@mcgp1.UUCP (Skip Tavakkolian) writes:
>Is there a way to execute something on exit, in Korn shell?
>This would be like the ``csh'' ``.logout'' file.

I use a statement in /etc/profile to accomplish this:

trap ". $HOME/.logout.ksh" 1

for this purpose, and it works just fine.

Wolf
-- 
Wolf N. Paul * 3387 Sam Rayburn Run * Carrollton TX 75007 * (214) 306-9101
UUCP:     killer!dcs!wnp                 ESL: 62832882
DOMAIN:   dcs!wnp@killer.dallas.tx.us    TLX: 910-380-0585 EES PLANO UD

connet@castor.usc.edu (David Connet) (10/03/88)

In article <415@motbos.UUCP> artp@motbos.UUCP (Art Parmet) writes:
>In your /etc/profile file add the following entry:
># run special program at logoff time
>trap "/local/bin/logoff" 0
>
>The file /local/bin/logoff (or whatever you choose to run) will be run when the
>parent shell of the user sesion dies.
>
>Regards,
>Art

Ummm, you had better add an exit in the trap, or after executing
/local/bin/logoff, you get your prompt back.

This is what I do:
	trap "logout;clear;exit" 0 3

logout is a shell script in my $HOME/bin that checks the existence
of $HOME/.logout.  It then dots that file.

Dave Connet

rchen@m.cs.uiuc.edu (10/04/88)

>Is there a way to execute something on exit, in Korn shell?
>This would be like the ``csh'' ``.logout'' file.

What I did was to disable "Ctrl-D" (I don't like it anyway) in the
login shell and at the same time alias "exit" or "logout" to whatever
I want.

-Ron Chen   Department of Computer Science
            University of Illinois at Urbana-Champaign
            rchen@cs.uiuc.edu

davidsen@steinmetz.ge.com (William E. Davidsen Jr) (10/05/88)

In article <209@dcs.UUCP> wnp@dcs.UUCP (Wolf N. Paul) writes:
| In article <1594@mcgp1.UUCP> fst@mcgp1.UUCP (Skip Tavakkolian) writes:
| >Is there a way to execute something on exit, in Korn shell?
| >This would be like the ``csh'' ``.logout'' file.
| 
| I use a statement in /etc/profile to accomplish this:
| 
| trap ". $HOME/.logout.ksh" 1

  This is an excellent answer to the problem, but there is a way to make
it more flexible. In my .profile I have code like this:

	for n in 0 1 3 15
	do	trap ". $HOME/.logout $n" $n
	done

and my .logout starts with:

	TermSIG="$1"

This allows me to make some tests in the logout script which avoid
loops. When just doing a normal termination I ask if all terminals
logged in under my ID are to be logged out, to allow me a fast way to
end the day. Others will probably want to use other tests.
-- 
	bill davidsen		(wedu@ge-crd.arpa)
  {uunet | philabs}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me

fst@mcgp1.UUCP (Skip Tavakkolian) (10/05/88)

In article <10680@ulysses.homer.nj.att.com>, ekrell@hector.UUCP (Eduardo Krell) writes:
> In article <1594@mcgp1.UUCP> fst@mcgp1.UUCP (Skip Tavakkolian) writes:
> >Is there a way to execute something on exit, in Korn shell?
> If you RTFM (or buy the book, that just came out) you'll see that
> "trap command 0" will do it.
> Eduardo Krell                   AT&T Bell Laboratories, Murray Hill, NJ
> UUCP: {att,decvax,ucbvax}!ulysses!ekrell  Internet: ekrell@ulysses.att.com

I am not a moron (although I may look it). I was looking for a builtin
solution; (one that may have not been documented).  Perhaps I should have
said ``and is not "trap `. $HOME/.logout` 0" ''.
Thanks to all those who responded.

Sincerely
-- 
Fariborz ``Skip'' Tavakkolian
UUCP	...!uw-beaver!tikal!mcgp1!fst

UNIX is a registered trademark of AT&T

tim@attdso.ATT.COM (Tim J Ihde) (10/05/88)

In article <1529@nunki.usc.edu> connet@castor.usc.edu (David Connet) writes:
>In article <415@motbos.UUCP> artp@motbos.UUCP (Art Parmet) writes:
>>trap "/local/bin/logoff" 0

>Ummm, you had better add an exit in the trap, or after executing
>/local/bin/logoff, you get your prompt back.

>This is what I do:
>	trap "logout;clear;exit" 0 3

Eh?  I've had

    trap '$HOME/.logout' 0

in my profile through several versions of ksh, and I never see my prompt
back.  If you trap with a signal number >0, then when the signal is
received the trap is executed and the shell resumes (so you would need
an exit); but signal number 0 is a special case:

	If 'n' is 0 then the command 'arg' is executed
	_on_exit_from_the_shell._		(User's Manual)

So the 0 trap is run during the exit, but does not interrupt the exit.
-- 
Tim J Ihde				UUCP:	    att!attdso!tim
(201) 898-6687				INTERNET:   tim@attdso.att.com
"Blimey - this redistribution of wealth is more complicated than I'd thought!"
		- Dennis Moore and misc. Presidents

cbp@foster.avid.OZ (Cameron Paine) (10/05/88)

In article <8620@smoke.ARPA>, gwyn@smoke.ARPA (Doug Gwyn ) writes:

> The following should work with any Bourne-compatible shell.
> [code deleted for brevity]

Unfortunately, this isn't so. If you change groups via newgrp during the
session, the trap is not inherited by the new instance of the shell.

cbp
-- 

cbp@foster.avid.oz - {ACS,CS}net
cbp%foster.oz.au@uunet.uu.net - ARPAnet
...!{hplabs,mcvax,nttlab,ukc,uunet}!munnari!foster.oz.au!cbp - UUCP
D

cdold@starfish.Convergent.COM (Clarence Dold) (10/06/88)

From article <1604@mcgp1.UUCP>, by fst@mcgp1.UUCP (Skip Tavakkolian):
> I am not a moron (although I may look it). I was looking for a builtin
> solution; (one that may have not been documented).  Perhaps I should have
> said ``and is not "trap `. $HOME/.logout` 0" ''.
Well, I liked it...
I do have one small problem though:
I also set TMOUT=3600.
If ksh times out while I have "trap..." set, I get a message 
ksh: setcooked failed  ksh: shelledit
and it doesn't do the .logout (which just posts .login + logout time to a file)
I want both the TMOUT and the '.logout' functions to work.

-- 
---
Clarence A Dold - cdold@starfish.Convergent.COM		(408) 435-5274
		...pyramid!ctnews!mitisft!professo!dold
		P.O.Box 6685, San Jose, CA 95150-6685

allbery@ncoast.UUCP (Brandon S. Allbery) (10/09/88)

As quoted from <1594@mcgp1.UUCP> by fst@mcgp1.UUCP (Skip Tavakkolian):
+---------------
| Is there a way to execute something on exit, in Korn shell?
| This would be like the ``csh'' ``.logout'' file.
+---------------

Try the command:

		trap ". ~/.logout" EXIT

Add extra traps to emulate csh ignoring of signals, etc.
-- 
Brandon S Allbery uunet!hal.cwru.edu!ncoast!allbery allbery%ncoast@hal.cwru.edu
(LAST RESORT ONLY:  allbery@uunet.uu.net)			DELPHI: ALLBERY
comp.sources.misc is moving off ncoast -- please do NOT send submissions direct
	  "So many articles, so little time...."  -- The Line-Eater

carroll@s.cs.uiuc.edu (10/10/88)

/* Written 11:53 am  Oct  6, 1988 by cdold@starfish.Convergent.COM in s.cs.uiuc.edu:comp.unix.wizards */
I do have one small problem though:
I also set TMOUT=3600.
If ksh times out while I have "trap..." set, I get a message 
ksh: setcooked failed  ksh: shelledit
and it doesn't do the .logout (which just posts .login + logout time to a file)
I want both the TMOUT and the '.logout' functions to work.
Clarence A Dold - cdold@starfish.Convergent.COM		(408) 435-5274
/* End of text from s.cs.uiuc.edu:comp.unix.wizards */

That's strange. I run ksh on a variety of systems (suns,3b2s,rts,vaxen) and
I have both 'trap "$HOME/.logout" EXIT' and 'TMOUT=600' set, and when
the shell times out, my .logout is executed, no problem.

Alan M. Carroll          "How many danger signs did you ignore?
carroll@s.cs.uiuc.edu     How many times had you heard it all before?" - AP&EW
CS Grad / U of Ill @ Urbana    ...{ucbvax,pur-ee,convex}!s.cs.uiuc.edu!carroll