home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / hp / 14123 < prev    next >
Encoding:
Text File  |  1992-12-16  |  3.5 KB  |  130 lines

  1. Newsgroups: comp.sys.hp
  2. Path: sparky!uunet!usc!cs.utexas.edu!torn!newshost.uwo.ca!news
  3. From: zaphod@ctrg.rri.uwo.ca (Lance R. Bailey)
  4. Subject: Re: wtmp, btmp getting to big !!!
  5. Reply-To: zaphod@ctrg.rri.uwo.ca
  6. Organization: University of Western Ontario
  7. Distribution: na
  8. Date: Wed, 16 Dec 1992 10:45:46 GMT
  9. Message-ID: <1992Dec16.104546.13468@julian.uwo.ca>
  10. References: <9235110.26727@mulga.cs.mu.OZ.AU>
  11. Sender: news@julian.uwo.ca (USENET News System)
  12. Nntp-Posting-Host: cossack.ctrg.rri.uwo.ca
  13. Lines: 115
  14.  
  15. In article <9235110.26727@mulga.cs.mu.OZ.AU> minh@lis.rch.unimelb.edu.au (Minh  
  16. Tran) writes:
  17. >    Is there way to delete entries in wtmp, btmp, they are really
  18. >    chewing up space, thanks.
  19.  
  20. the traditional way is to cp /dev/null or otherwise zap them out. infact,
  21. accounting zaps them out daily. unfortunatly, this means that you have NO 
  22. record of who was last on and when.
  23.  
  24. i have a program called startwtmp which massages the wtmp file into keeping
  25. records of the last time anyone was on the machine. it's been running for 
  26. years on my systems each night. handles up to 1000 uids, easily expanded.
  27.  
  28. i attach it below the sig.
  29. --
  30. Lance R. Bailey  System/Network Manager         Robarts Research Institute
  31.      NeXT/email: zaphod@ctrg.rri.uwo.ca    box: Clinical Trials Resources Group
  32.             fax: +1 519 663 3789                P.O. Box 5015, 100 Perth Dr.
  33.             vox: +1 519 663 3787 x4108          London, Canada N6A 5K8
  34. She's human...well, she's a lawyer, but reasonably human. -Professor Ralph  
  35. Noble
  36.  
  37. #include <stdio.h>
  38. #include <sys/types.h>
  39. #include <utmp.h>
  40. #include <time.h>
  41.  
  42. extern struct utmp *getutent();
  43. int compareutmp();
  44.  
  45. #define MAXUSER 8
  46. #define MAXENTRIES 1000
  47.  
  48. main(argc,argv) char **argv; int argc;
  49. {   struct utmp *utent;
  50.     struct utmp utsave[MAXENTRIES];
  51.     struct utmp utlogin;
  52.     int nEnt=0,i;
  53.  
  54.     utmpname(argv[1]); utent = getutent();
  55.  
  56.     while (utent != NULL)
  57.     {   if (utent->ut_type != USER_PROCESS && utent->ut_type != BOOT_TIME)
  58.         {   if (utent->ut_type == LOGIN_PROCESS) utlogin = *utent;
  59.             utent = getutent(); continue;
  60.         }
  61.  
  62.         if (!strncmp(utent->ut_user,"INVALID",7)) {utent =  
  63. getutent();continue;}
  64.  
  65.         if (utent->ut_type == USER_PROCESS)
  66.         {   if ((i,i=finduser(utent,utsave,nEnt))<0) utsave[nEnt++]=*utent; 
  67.             else utsave[i] = *utent;
  68.         }
  69.         else utsave[nEnt++]=*utent;   /* save all boots */
  70.  
  71.         utent = getutent();
  72.     }
  73.  
  74.     qsort(utsave,nEnt,sizeof(struct utmp),compareutmp);
  75.     for (i=0;i<nEnt;i++)
  76.     {   write(1,utsave[i],sizeof(struct utmp));
  77.         if (utsave[i].ut_type == BOOT_TIME) continue;
  78. /*
  79.  * check the utmp for this entry, if none, fake a login process
  80.  */
  81.         if (!utmpEnt(utsave[i]))
  82.         {   strncpy(utlogin.ut_id,utsave[i].ut_id,4);
  83.             strncpy(utlogin.ut_line,utsave[i].ut_line,12);
  84.             utlogin.ut_time = utsave[i].ut_time+1;
  85.             write(1,utlogin,sizeof(struct utmp));
  86.         }
  87.     }
  88.  
  89.     exit(0);
  90. }
  91.  
  92.  
  93.  
  94. int compareutmp(a,b) struct utmp a,b;
  95. {  if (a.ut_time < b.ut_time ) return -1;
  96.    if (a.ut_time > b.ut_time ) return 1;
  97.    return 0;
  98. }
  99.  
  100.  
  101.  
  102. finduser(e,l,n) struct utmp *e;
  103.                 struct utmp l[MAXENTRIES];
  104.     int n;
  105. {   while (n>=0) 
  106.     {   if (!strncmp(e->ut_user,l[n].ut_user,MAXUSER)) return n;
  107.         n--;
  108.     }
  109.     return -1;
  110. }
  111.  
  112.  
  113.  
  114. utmpEnt(id) struct utmp id;
  115. {   struct utmp *uts;
  116.  
  117.     utmpname("/etc/utmp");
  118.     if (uts,uts=getutline(id)) if(id.ut_pid==uts->ut_pid){endutent();return 1;}
  119.  
  120.     endutent(); return 0;
  121. }
  122.  
  123.  
  124.  
  125.  
  126. /*
  127.  * EOF
  128.  */
  129.  
  130.