Skip to content

Instantly share code, notes, and snippets.

@bigntallmike
Created June 2, 2021 15:22
Show Gist options
  • Save bigntallmike/d420637f5c48c2b2b5f46972b4a29c72 to your computer and use it in GitHub Desktop.
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
#!/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