Created
June 2, 2021 15:22
-
-
Save bigntallmike/d420637f5c48c2b2b5f46972b4a29c72 to your computer and use it in GitHub Desktop.
Needed a script to remove entries from gshadow that weren't in groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# | |
# After editing /etc/groups, generate a gshadow without the missing entries | |
def main(): | |
groups = [] | |
for groupname, other in readgroupnames("/etc/group"): | |
groups.append(groupname) | |
print(groups) | |
with open("/tmp/gshadow.new", "w") as newgroups: | |
for groupname, other in readgroupnames("/etc/gshadow"): | |
if groupname in groups: | |
newgroups.write(":".join([groupname, other])) | |
else: | |
print("Delete: %s" % groupname) | |
def readgroupnames(filename): | |
with open(filename, "r") as groupdata: | |
for line in groupdata: | |
(groupname, other) = line.split(":", 1) | |
yield groupname, other | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment