Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!bria!mike Newsgroups: comp.unix.admin Subject: Re: Overflowing wtmp Keywords: wtmp cron cleanup Message-ID: <404@bria> Date: 28 Jan 91 00:00:01 GMT References: <92@tdatirv.UUCP> <1991Jan23.150231.608@truevision.com> <390@bria> Organization: Briareus Corporation, Los Angeles, CA Lines: 95 Since quite a few people have requested it, and because it isn't too long, I'll just throw my flavor of fwtmp up here: ---[ cut here ]---------------------------------------------------------------- /* @(#)fwtmp.c 1.1 90/02/16 convert utmp to ascii and back written by Michael Stefanik This program is for public consumption and is therefore a "user supported" program. The buck stops with you. This program was written to act similarly to the fwtmp(1) on our AIX machine. It can be installed anywhere, I prefer /etc myself. Fwtmp(1) has a few simple uses: to trim down growing /etc/wtmp files, and to expand /etc/utmp for whatever reasons. Without the -ic switch, fwtmp assumes stdin is in utmp format, and writes ascii to stdout; with the -ic switch, the assumption is reversed */ #include #include #include #include #define UTSIZE (sizeof(struct utmp)) char *image; main(argc,argv) int argc; char *argv[]; { image = argv[0]; if ( argc == 2 && strcmp(argv[1],"-ic") == 0 ) toutmp(); else if ( argc == 1 ) fromutmp(); else { fprintf(stderr,"Usage: %s [-ic] file\n",image); return(1); } return(0); } toutmp() { char buf[128], *ptr, *strtok(); struct utmp u; while ( gets(buf) != NULL ) { strncpy(u.ut_user,strtok(buf," "),8); strncpy(u.ut_id,strtok(NULL," "),4); strncpy(u.ut_line,strtok(NULL," "),12); u.ut_pid = (short)atoi(strtok(NULL," ")); u.ut_type = (short)atoi(strtok(NULL," ")); u.ut_exit.e_termination = (short)atoi(strtok(NULL," ")); u.ut_exit.e_exit = (short)atoi(strtok(NULL," ")); u.ut_time = (time_t)atol(strtok(NULL," ")); if ( write(1,&u,UTSIZE) != UTSIZE ) { fprintf(stderr,"%s: write failed\n",image); exit(1); } } } fromutmp() { int bytes; struct utmp u; while ( (bytes = read(0,&u,UTSIZE)) == UTSIZE ) printf("%s %s %s %d %d %d %d %ld\n", u.ut_user, u.ut_id, u.ut_line, (int)u.ut_pid, (int)u.ut_type, (int)u.ut_exit.e_termination, (int)u.ut_exit.e_exit, u.ut_time); if ( bytes != 0 ) { fprintf(stderr,"%s: corrupt utmp file\n",image); exit(1); } } ------------------------------------------------------------------------------- Hope this helps keep you in your efforts to keep your disk on a low-fat diet. :-) -- Michael Stefanik, Systems Engineer (JOAT), Briareus Corporation UUCP: ...!uunet!bria!mike -- technoignorami (tek'no-ig'no-ram`i) a group of individuals that are constantly found to be saying things like "Well, it works on my DOS machine ..."