Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!rutgers!mtune!whuts!homxb!ihnp4!occrsh!occrsh.ATT.COM!rjd From: rjd@occrsh.ATT.COM Newsgroups: comp.sys.att Subject: Re: Using 'exit' in a Bourne shell scri Message-ID: <144800023@occrsh.ATT.COM> Date: 2 Feb 88 18:40:00 GMT References: <169@mccc.UUCP> Lines: 40 Nf-ID: #R:mccc.UUCP:-16900:occrsh.ATT.COM:144800023:000:2019 Nf-From: occrsh.ATT.COM!rjd Feb 2 12:40:00 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