[comp.unix.questions] Is there a Bourne-shell .logout script?

jc@cdx39.UUCP (John Chambers) (12/02/86)

OK, all you shell experts out there, here's the question of
the day for y'all.

The C-shell runs a script called $home/.logout when you tell
it to log you out.  Is there any way to get the Bourne shell
to do something similar?

What we have is a situation where a lot of users need to run
one of several commands when they logout, and for C-shell users,
it's easy.  We have a small coterie of Bourne-shell users who
want to have the same "automatically run .foo on logout" that
the C-shell users use.  

I'd hate to have to tell them to use the C-shell; they'd just
have to unlearn it all when we get a K-shell.  {:-}

-- 
	John M Chambers			Phone: 617/364-2000x7304
Email: ...{adelie,harvax,inmet,mcsbos,mit-eddie,mot[bos],rclex}!cdx39!{jc,news,root,usenet,uucp}
Smail: Codex Corporation; Mailstop C1-30; 20 Cabot Blvd; Mansfield MA 02048-1193

rob@ptsfb.UUCP (Rob Bernardo) (12/03/86)

In article <502@cdx39.UUCP> jc@cdx39.UUCP (John Chambers) writes:
>The C-shell runs a script called $home/.logout when you tell
>it to log you out.  Is there any way to get the Bourne shell
>to do something similar?

How about putting:
	trap "$HOME/.logout" 0
in your .profile (or in /etc/profile)?

ken@rochester.ARPA (SKY) (12/04/86)

In article <502@cdx39.UUCP> jc@cdx39.UUCP (John Chambers) writes:
|The C-shell runs a script called $home/.logout when you tell
|it to log you out.  Is there any way to get the Bourne shell
|to do something similar?

Sure, just say trap 'command' 0 in your .profile.

	Ken

gwyn@brl-smoke.ARPA (Doug Gwyn ) (12/04/86)

In article <502@cdx39.UUCP> jc@cdx39.UUCP (John Chambers) writes:
>The C-shell runs a script called $home/.logout when you tell
>it to log you out.  Is there any way to get the Bourne shell
>to do something similar?

To run such a script upon termination of your login shell,
add something like the following to your .profile:

if [ -r $HOME/.foo ]
then	trap '. $HOME/.foo' 0
fi

jerryp@tektools.UUCP (Jerry Peek) (12/05/86)

In article <1051@ptsfb.UUCP> rob@ptsfb.UUCP (Rob Bernardo) writes:
> In article <502@cdx39.UUCP> jc@cdx39.UUCP (John Chambers) writes:
> >The C-shell runs a script called $home/.logout when you tell
> >it to log you out.  Is there any way to get the Bourne shell
> >to do something similar?
> 
> How about putting:
> 	trap "$HOME/.logout" 0
> in your .profile (or in /etc/profile)?

Not quite.  Unless your Bourne Shell is different than mine (4.3BSD),
this trap *starts a child Bourne Shell* to read the .logout file.
This means that shell variables and stuff you've set in your
login shell *won't be available* when the .logout file is read.

On the other hand, in the C-shell, the .logout file is read *directly by
the login shell*.  This lets your .logout test for the presence of shell
variables which were set in the login shell.  For instance, I set up some
shell variables that tell me whether the login shell came from a remote
machine (rlogin) or not, and do different things in those cases.

The fix is easy... use this "trap" instead:
 	trap ". $HOME/.sh_logout" 0
The leading "." tells the login Bourne shell to read the ".sh_logout" file
directly into itself, instead of spawning a child shell.  (I name mine
".sh_logout" because it has Bourne-shell contents that csh would choke on.)

--Jerry Peek, Tektronix, Inc.
US Mail:      MS 74-900, P.O. Box 500, Beaverton, OR 97077
uucp-style:   {allegra,decvax,hplabs,ihnp4,ucbvax}!tektronix!tektools!jerryp
Domain-style: jerryp@tektools.TEK.COM
Phone:        +1 503 627-1603

cgs@umd5.UUCP (12/09/86)

In article <1950@tektools.UUCP> jerryp@tektools.UUCP (Jerry Peek) writes:
>In article <1051@ptsfb.UUCP> rob@ptsfb.UUCP (Rob Bernardo) writes:
>> In article <502@cdx39.UUCP> jc@cdx39.UUCP (John Chambers) writes:
>> >The C-shell runs a script called $home/.logout when you tell
>> >it to log you out.  Is there any way to get the Bourne shell
>> >to do something similar?
>> 
>> How about putting:
>> 	trap "$HOME/.logout" 0
>> in your .profile (or in /etc/profile)?
>
>Not quite.  Unless your Bourne Shell is different than mine (4.3BSD),
>this trap *starts a child Bourne Shell* to read the .logout file.
>This means that shell variables and stuff you've set in your
>login shell *won't be available* when the .logout file is read.
>
> ...
>The fix is easy... use this "trap" instead:
> 	trap ". $HOME/.sh_logout" 0
>The leading "." tells the login Bourne shell to read the ".sh_logout" file
>directly into itself, instead of spawning a child shell.  (I name mine
>".sh_logout" because it has Bourne-shell contents that csh would choke on.)
>

Unless your "man page" for "sh" is different than mine (4.3BSD),
the first trap will perform the function desired, while 'trap ". foo" 0'
will execute the file 'foo' AND RETURN when signal 0 is encountered. See
the section entitled "Special Commands".

-- 
--==---==---==--
.. And hast thou slain the Jabberwock? ..

ARPA: cgs@umd5.UMD.EDU     BITNET: cgs%umd5@umd2
UUCP: ..!seismo!umd5.umd.edu!cgs