1 /* 2 * Copyright (c) 1983 Eric P. Allman 3 * Copyright (c) 1988 Regents of the University of California. 4 * All rights reserved. 5 * 6 * %sccs.include.redist.c% 7 * 8 */ 9 10 #ifndef lint 11 char copyright[] = 12 "@(#) Copyright (c) 1988 Regents of the University of California.\n\ 13 All rights reserved.\n"; 14 #endif /* not lint */ 15 16 #ifndef lint 17 static char sccsid[] = "@(#)mailstats.c 5.7 (Berkeley) 06/01/90"; 18 #endif /* not lint */ 19 20 #include <sys/file.h> 21 #include <sendmail.h> 22 #include <mailstats.h> 23 #include "pathnames.h" 24 25 main(argc, argv) 26 int argc; 27 char **argv; 28 { 29 extern char *optarg; 30 extern int optind; 31 struct statistics stat; 32 register int i; 33 int ch, fd; 34 char *sfile, *ctime(); 35 36 sfile = _PATH_MAILSTATS; 37 while ((ch = getopt(argc, argv, "f:")) != EOF) 38 switch((char)ch) { 39 case 'f': 40 sfile = optarg; 41 break; 42 case '?': 43 default: 44 fputs("usage: mailstats [-f file]\n", stderr); 45 exit(EX_USAGE); 46 } 47 argc -= optind; 48 argv += optind; 49 50 if ((fd = open(sfile, O_RDONLY)) < 0) { 51 fputs("mailstats: ", stderr); 52 perror(sfile); 53 exit(EX_NOINPUT); 54 } 55 if (read(fd, &stat, sizeof(stat)) != sizeof(stat) || 56 stat.stat_size != sizeof(stat)) { 57 fputs("mailstats: file size changed.\n", stderr); 58 exit(EX_OSERR); 59 } 60 61 printf("Statistics from %s", ctime(&stat.stat_itime)); 62 printf(" M msgsfr bytes_from msgsto bytes_to\n"); 63 for (i = 0; i < MAXMAILERS; i++) 64 if (stat.stat_nf[i] || stat.stat_nt[i]) 65 printf("%2d %6ld %10ldK %6ld %10ldK\n", i, 66 stat.stat_nf[i], stat.stat_bf[i], 67 stat.stat_nt[i], stat.stat_bt[i]); 68 exit(0); 69 } 70