Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!brl-adm!brl-smoke!smoke!bzs%bostonu.csnet@csnet-relay.arpa From: bzs%bostonu.csnet@csnet-relay.arpa (Barry Shein) Newsgroups: net.unix-wizards Subject: Re: UNIX per-process accounting Message-ID: <2570@brl-smoke.ARPA> Date: Fri, 11-Apr-86 13:45:46 EST Article-I.D.: brl-smok.2570 Posted: Fri Apr 11 13:45:46 1986 Date-Received: Wed, 16-Apr-86 03:28:49 EST Sender: news@brl-smoke.ARPA Lines: 43 To summarize, Fred Toth is looking for a way to charge work to customers using a SUN3 in a manner similar to that provided through kernel mods in previous systems. The hook seems to be that when work is done for a customer it is done in a particular directory. I've got it (I think): Assuming you can/will set the group of the directory to something indicative of which customer is involved (say, their name), you could create a .cshrc alias for 'cd' which will grovel out the group name (this could be done most easily by writing a little C program which just does a stat on the target, looks up the group name and prints it to the standard output so it can be used in a backquote arg, or you can grovel a 'ls -ldg' with sed or awk.) Then, write a null program with the same name as the group, this is run on each 'cd' simply to leave it's accounting stamp in the accounting file. Then, when you run through the accounting files you have windows between the running of each group name to charge. done. Ok, that's pretty obscure, so here's some code: let us say that directory xyzzy has group ownership Joe, that a program 'pgroup' is written which simply prints out the group field to the standard output and there exists a program 'Joe' which does nothing but just run (main(){ exit(0);}). An alias might be: alias CD '`pgroup \!^`;cd \!^' Now if you do a lastcomm after running that program it should reveal that your user just ran a program named Joe, thus you know to start charging all subsequent jobs to the account 'Joe'. When he cd's somewhere else, a new group will be stamped in the accounting file (or, s/he can use good ole 'cd' rather than 'CD' if that's not his/her intention.) (That is, 'CD xyzzy' expands to '`pgroup xyzzy`;cd xyzzy' which expands to 'Joe;cd xyzzy'. I tried an example, it should work.) Done. (I think.) No kernel hacks, 10 minutes work. I suppose some sort of pushdown approach could be done, but that's left as an exercise for the reader :-) If that's not clear ask, but ask fast, I'm gonna forget this one real fast I think. Also, give a thought to security. -Barry Shein, Boston University