Using 'exit' in a Bourne shell scri

rjd at occrsh.ATT.COM rjd at occrsh.ATT.COM
Wed Feb 3 04:40:00 AEST 1988


>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



More information about the Comp.sys.att mailing list