[comp.sys.att] Using 'exit' in a Bourne shell scri

rjd@occrsh.ATT.COM (02/03/88)

>The exit in your shell script is only going to get you out of that
>script.  In fact, sending exit codes is one way of communicating between
>scripts ( if [ script exits with a number "n" ] then ...).
>
>A friend of mine solved that problem thusly.  He was only interested
>in his own .profile, but
>
>	trap '$HOME/.logout' 0
>
>Which is to say, "when you receive the logoff signal, execute $HOME/.logout
>first and THEN log off."  I believe there's probably a problem with this,
>though:  Traps can be reset, so a user could, as I understand it, ask to
>have something else happen at signal 0 , thereby negating what you're
>trying to do.  Someone correct me if I'm wrong about this (I'm sure
>someone will) 'cuz I'd like to know.
>
>Kathy Vincent ------>  {ihnp4|mtune|codas|ptsfa}!bakerst!kathy

  Yes, traps can be reset or canceled by the owner, who is the one who
set it anyway (whether he knows it or not).  I used to set the trap in
/etc/profile for all users to run a setuid binary that simply executed
a system() call to run the shell script to record their actions.  The
only problem with this method is as you mentioned: the user can get around
it easily, if he/she is aware of it.
  What I found to be the easiest way was to use what is already built in
to the system: the /etc/wtmp file.  All you need to do is "who -ud /etc/wtmp"
for a complete listing of all logins and logouts since the wtmp file was
last erased.  The wtmp file is written by getty and other processes, which
together keep a complete set of system time changes (at least those made
via the date(1) command - system calls within a binary are not recorded
unless you put the code to record it), system boot times, etc....

  Now, I was assuming that all you wanted to do was record logins and
logouts, as the first script implied.  If you need a specific action
performed, you might consider having cron do a who(1) once a minute and
comparing the output from the previous minute for missing people and do
actions based on that.

Randy

rjd@occrsh.ATT.COM (02/05/88)

>>>I would like to have my users logout via a shell script "off" rather
>>>than with ^d.  The script I wrote is very simple, but 'exit' has no
>>>effect. ...
>> 
>> 	trap '$HOME/.logout' 0
>
>As you mentioned, exit will only get you out of the script, not the
>enwrapped shell.  I've always had good luck with:
>
>	kill -9 0
>
>in a shell script.  This is a bit rough (as it kills ALL programs associated
>with the terminal, including background ones), but it has to be since a
>normal kill is ignored by the shell.  I'm sure there is a better way, too...

  It can be dangerous if root uses a 'kill -? 0'.....

On the subject of "stty 0" - It is *supposed* to do a hangup and other things,
but in some instances it locks up the terminal driver device (at least on some
systems...)

Randy