Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!hoptoad!well!ptsfa!lll-tis!ohlone!lll-winken!uunet!husc6!bbn!uwmcsd1!marque!ddsw1!karl From: karl@ddsw1.UUCP Newsgroups: alt.sources Subject: Short 'n' dirty file space totaller Message-ID: <239@ddsw1.UUCP> Date: Mon, 5-Oct-87 18:15:58 EDT Article-I.D.: ddsw1.239 Posted: Mon Oct 5 18:15:58 1987 Date-Received: Sat, 10-Oct-87 14:51:16 EDT Organization: Traveller's Aid (ddsw1), Chicago Ill. Lines: 59 Keywords: Microport (or is it system V) disk utility Here's a real short, cheap-n-dirty disk usage tracker. Pipe the output of this program through sort(1) with the proper options, and you've got a nice report of who's the biggest disk pig on your system. Note that this is a CHEAP AND DIRTY way of doing the job, it's not optimized, scrunched, or even reasonanbly conscientious about resource consumption. It also won't find files that are deliberately hidden (ie: not in a user's $HOME). It requires that the utility 'du' be on the system somewhere in your PATH. Lastly, it's unsupported, and has no man page. But what do you want for a thousand bytes of 'C' or thereabouts. It does write errors to stderr, and output to standard output (stdout), so at least you can separate errors (and warnings) from the useful part. This code is hereby deemed public domain. Do what you want with it. /* Make a disk usage report */ /* Authored sometime in 1987 by Karl Denninger because we needed it to keep track of the disk pigs on our system */ #include #include #include #include #include extern struct passwd *getpwent(); main() { struct passwd *psw; FILE *fid; char tmp[80]; while ((psw = getpwent()) != NULL) { if (psw->pw_uid >= 100) { /* Ignore < 100 */ if ((open(psw->pw_dir, O_CREAT|O_EXCL,000) < 0 ) && (errno = EISDIR)) { printf("%12s: ", psw->pw_name); fflush(stdout); strcpy(tmp, "cd "); strcat(tmp, psw->pw_dir); strcat(tmp, ";du|tail -1|cut -d. -f1"); /* How many blocks? */ system(tmp); fflush(stdout); } else { unlink(psw->pw_dir); fprintf(stderr,"No directory for %s (%d)\n", psw->pw_name, psw->pw_uid); } } else fprintf(stderr,"Skipped user %s (%d)\n",psw->pw_name, psw->pw_uid); } fclose(fid); exit(0); } -- Karl Denninger UUCP : ...ihnp4!ddsw1!karl Macro Computer Solutions Dial : +1 (312) 566-8909 (300-1200) "Quality solutions at a fair price" Voice: +1 (312) 566-8910 (24 hrs)