#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  accutil.c accutil.doc
# Wrapped by brant@manta on Tue Feb 14 14:45:38 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'accutil.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'accutil.c'\"
else
echo shar: Extracting \"'accutil.c'\" \(1110 characters\)
sed "s/^X//" >'accutil.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/acct.h>
X#include <time.h>
X#include <fcntl.h>
X
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X
X{
X	struct acct abuf;
X	char *ctime();
X	int fd;
X
X	fd = 0;
X	if (strcmp(argv[1], "-e") == 0) {
X		if (argc != 3)
X			usage();
X		if (acct(argv[2]) < 0) {
X			fprintf(stderr, "Can't enable accounting on file %s\n",
X			argv[2]);
X			exit(1);
X		}
X		exit(0);
X	}
X	else if (strcmp(argv[1], "-d") == 0) {
X		if (argc != 2)
X			usage();
X		if (acct(NULL) < 0) {
X			fprintf(stderr, "Can't disable accounting\n");
X			exit(1);
X		}
X		exit(0);
X	}
X	else if (strcmp(argv[1], "-f") == 0) {
X		if ((fd = open(argv[2], O_RDONLY)) < 0) {
X			fprintf(stderr, "Can't open %s\n", argv[2]);
X			exit(1);
X		}
X	}
X	else if (argc != 1)
X		usage();
X	printf("  COMMAND  UID GID   TTY FLG EXIT           TIME\n");
X	while (read(fd, & abuf, sizeof(abuf)) > 0)
X		printf("%10s%4d%4d%6d%4d%4d  %s",
X		abuf.ac_comm,
X		abuf.ac_uid,
X		abuf.ac_gid,
X		abuf.ac_tty,
X		abuf.ac_flag,
X		abuf.ac_stat,
X		ctime(& abuf.ac_btime));
X}
X
Xusage()
X
X{
X	fprintf(stderr, "Usage:  acctutil [{-e file} | {-d} | {-f file}]\n");
X	exit(1);
X}
END_OF_FILE
if test 1110 -ne `wc -c <'accutil.c'`; then
    echo shar: \"'accutil.c'\" unpacked with wrong size!
fi
# end of 'accutil.c'
fi
if test -f 'accutil.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'accutil.doc'\"
else
echo shar: Extracting \"'accutil.doc'\" \(1724 characters\)
sed "s/^X//" >'accutil.doc' <<'END_OF_FILE'
XFrom cgh!amanue!jr Fri Aug 21 22:56:54 EST 1987
XArticle 9 of unix-pc.sources:
XPath: manta!cgh!amanue!jr
X>From: jr@amanue.UUCP (Jim Rosenberg)
XNewsgroups: unix-pc.sources
XSubject: Process accounting utility
XKeywords: acct(2)
XMessage-ID: <234@amanue.UUCP>
XDate: 20 Aug 87 04:03:14 GMT
XOrganization: Amanuensis Inc., Grindstone, PA
XLines: 96
X
XEnclosed is a little utility I wrote for VENIX which turns on and off process
Xaccounting, and prints the accounting log.  There are some fields I haven't
Xprinted out; perusing /usr/include/sys/acct.h will show you what they are; but
Xthis should include the most crucial ones.  I'm frankly not really sure what
Xthe "accounting flag" entry really means.
X
XTo turn on process accounting, give the command
X
Xacctutil -e filename
X
X(BUG:  The file must *already* exist.)
X
XTo turn off process accounting give the command
X
Xacctutil -d
X
XTo see a report of the activity give the command
X
Xacctutil -f file
X
XNo flames please, this was a *very* quick hack, and could use all kinds of
Xamenities, like printing the log in reverse order.  If you're wondering what
Xkind of things go bump in the night spawned by the User Agent, you might leave
Xprocess accounting on for a while and see what programs are being spawned.
XNote that if you enable process accounting you should clean out the logs daily
Xfrom cron, or they will become humongous.  Process accounting is also a rather
Xuseful way of finding out what was going on just prior to a crash.
X
X[ moved to /usr/local/src/accutil -bc ]
X
X-- 
X Jim Rosenberg
X     CIS: 71515,124                         decvax!idis! \
X     WELL: jer                                   allegra! ---- pitt!amanue!jr
X     BIX: jrosenberg                 seismo!cmcl2!cadre! /
X
X
END_OF_FILE
if test 1724 -ne `wc -c <'accutil.doc'`; then
    echo shar: \"'accutil.doc'\" unpacked with wrong size!
fi
# end of 'accutil.doc'
fi
echo shar: End of shell archive.
exit 0

