From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96079336919163.tru64-unix-managers.marc@archive.invalid> From: George Gallen Date: Tue, 01 Feb 2000 22:59:05 +0000 To: tru64-unix-managers Subject: SUMMARY: cleaning up /etc/group file X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96079336919163 didn't get too many suggestions. Thank you to all who replied. ----------------------------------------------------------------------- A couple to use grpck, but that only tells me what I already knew, that I had users in /etc/group that are not in /etc/passwd. Granted it told me which ones. ------------------------------------------------------------------------ one perl script from Oisin McGuinness ------------------------------------------------------------------------ OK, here is a quick and dirty perl script, which you can use like this: rmuser user-name >new-group-file mv new-group-file /etc/group It handles the cases where the user name occurs at the end of a line, is a substring of other names etc. No guarantee.... Oisin McGuinness #!/usr/local/bin/perl # # Remove user name from group file. # # Usage: rmuser username # output: new version of group file. # $grpfile = "/etc/group" ; require 'ctime.pl' ; if($#ARGV < 0) { die "Must specify user name.\n" ; } $user = $ARGV[0] ; open(GRPFILE, "<$grpfile") || die "can't read $grpfile: $!\n" ; while() { chomp ; # NIS entry if(/^\+:/) { print $_,"\n" ; next ; } ($group,$pwd,$id,$members) = split(/:/) ; $members =~ s/\b$user\b//g ; # match at boundaries only $members =~ s/,,/,/ ; # possible two commas introduced. $members =~ s/,$// ; # possible comma at end of line created. print "$group:$pwd:$id:$members\n" ; } close(GRPFILE) ; --------------------------------------------------------------------------- And if your lucky enough to be running PICK on Unix (if you don't know what it is, you aren't running it! :) ) Here is the routine I came up with: --------------------------------------------------------------------------- 0001: * This program will read the /etc/group file and 0002: * check each username against the /etc/passwd file 0003: * to see if they are still active accounts, if not 0004: * it will remove them. 0005: * 0006: * YOU MUST HAVE SUPERUSER RIGHTS to run this program 0007: * 0008: * MAKE SURE NO ONE IS UPDATING /etc/group while this 0009: * program is running, As I'm not sure what the effect 0010: * would be to READU and lock a unix system file, if 0011: * any to unix. 0012: * 0013: * 0014: ******************************************************* 0015: * 0016: OPENPATH "/etc" TO F.ETC ELSE STOP 0017: * 0018: READ PASSWD FROM F.ETC,"passwd" ELSE STOP "CAN'T READ PASSWD FILE" 0019: READ GROUP FROM F.ETC,"group" ELSE STOP "CAN'T READ GROUP FILE" 0020: * 0021: PASSWD=FIELDS(PASSWD,":",1) 0022: * 0023: * INSERT ANY ENTRIES THAT ARE ACCEPTABLE TO KEEP IN /etc/group 0024: * THAT ARE NOT IN /etc/passwd HERE 0025: * 0026: INS "mail" BEFORE PASSWD<-1> 0027: * 0028: NEWGROUP="" 0029: * 0030: FOR T=1 TO DCOUNT(GROUP,CHAR(254)) 0031: GRPNM=FIELD(GROUP,":",1) 0032: GRPPS=FIELD(GROUP,":",2) 0033: GRPNO=FIELD(GROUP,":",3) 0034: USERS=FIELD(GROUP,":",4) 0035: CONVERT "," TO CHAR(254) IN USERS 0036: FOR Q=DCOUNT(USERS,CHAR(254)) TO 1 STEP -1 0037: UNAME=USERS 0038: NFND=0 0039: LOCATE UNAME IN PASSWD<1> SETTING POS ELSE NFND=1 0040: IF NFND=1 THEN 0041: DEL USERS 0042: END 0043: NEXT Q 0044: CONVERT CHAR(254) TO "," IN USERS 0045: NEWGRP=GRPNM:":":GRPPS:":":GRPNO:":":USERS 0046: INS NEWGRP BEFORE NEWGROUP<-1> 0047: NEXT T 0048: WRITE NEWGROUP ON F.ETC,"group" 0049: * 0050: STOP 0051: END 0052: * -----Original Message----- From: George Gallen [mailto:ggallen@slackinc.com] Sent: Tuesday, February 01, 2000 1:51 PM To: 'tru64-unix-managers@ornl.gov' Subject: cleaning up /etc/group file Now that we have been adding accounts and deleteing accounts for a few years, our /etc/group file still has all the accounts created, (apparantly, removeuser doesn't sift through /etc/group and remove the account from there as well). Does anyone know of a script or program that will clean up /etc/group of any non-existant account names? I'm currently on 3.2c (and it's still working fine in y2k!! :) ) Thanks George Gallen Senior Programmer/Analyst Accounting/Data Division ggallen@slackinc.com ph:856.848.1000 Ext 220 SLACK Incorporated - An innovative information, education and management company http://www.slackinc.com