[alt.hackers] quota dumping program -- now you too can see your syadmin's quota :-)

subbarao@PHOENIX.PRINCETON.EDU (Kartik Subbarao) (03/28/91)

Here's a neat little program that will dump the quota of the user specified
on the command line. It works with NFS, and depends on the file
"directory/quotas" being readable. It was a ten minute hack, so there's
no error checking. Have fun!

# include <stdio.h>
# include <pwd.h>

main(int argc, char *argv[])
{
	int uid, i;
	long q[8];
	char fs[50], qstr[50], pipel[100];
	FILE *fsys, *qfp;
	struct passwd *pwd;
	strcpy(pipel, "df ");
	if (argc != 2) {fprintf(stderr, "usage: %s username\n", argv[0]); exit(1);}
	pwd = getpwnam(argv[1]);
	strcat(pipel, pwd->pw_dir); strcat(pipel, "|tail +2|awk '{print $6}'");
	fsys = popen(pipel, "r"); fscanf(fsys, "%s", fs); pclose(fsys);
	sprintf(qstr, "%s/quotas", fs); qfp = fopen(qstr, "r"); 
	fseek(qfp, pwd->pw_uid*32, 0); fread(q,8,4,qfp);
	printf("Disk quotas for %s (uid %d):\n", argv[1], pwd->pw_uid);
	printf("Filesystem\tusage\tquota\tlimit\tfiles\tquota\tlimit\n");
printf("%s\t%d\t%d\t%d\t%d\t%d\t%d\n",fs,q[2]/2,q[1]/2,q[0]/2,q[5],q[4],q[3]);
}

--
internet# find . -name core -exec cat {} \; |& tee /dev/tty*
subbarao@phoenix.Princeton.EDU -| Internet
kartik@silvertone.Princeton.EDU (NeXT mail)  
SUBBARAO@PUCC.BITNET			          - Bitnet