Skip to content

Instantly share code, notes, and snippets.

@vijayanandrp
Created June 14, 2017 20:39
Show Gist options
  • Save vijayanandrp/cf93fbf4d6c066b6069e1abcfb54e7ae to your computer and use it in GitHub Desktop.
Save vijayanandrp/cf93fbf4d6c066b6069e1abcfb54e7ae to your computer and use it in GitHub Desktop.
pwd quick example
#!/usr/bin/python
import pwd
from tabulate import tabulate
def main():
pwd_headers = ["pw_name", "pw_passwd", "pw_uid", "pw_gid", "pw_gecos", "pw_dir", "pw_shell"]
passwd_entries = pwd.getpwall()
pwd_list = []
for (pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell) in passwd_entries:
pwd_list.append([pw_name, pw_passwd, str(pw_uid), str(pw_gid), pw_gecos, pw_dir, pw_shell])
#for entry in passwd_entries:
# pwd_list.append([entry.pw_name, entry.pw_passwd, str(entry.pw_uid), str(entry.pw_gid), entry.pw_gecos, entry.pw_dir, entry.pw_shell])
print tabulate(pwd_list, pwd_headers, tablefmt='rst')
if __name__ == "__main__":
main()
print pwd.getpwuid(0)
print pwd.getpwnam('root')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment