Created
November 29, 2013 16:03
-
-
Save tjjh89017/7707863 to your computer and use it in GitHub Desktop.
This file contains 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/env python | |
# -*- coding: utf8 -*- | |
import os | |
import sys | |
import string | |
import random | |
def passwd_generator(size = 6, chars = string.ascii_uppercase + string.ascii_lowercase + string.digits): | |
return "".join(random.choice(chars) for x in xrange(size)) | |
if __name__ == "__main__": | |
uid_start = int(sys.argv[1]) | |
account_list = None | |
with open(sys.argv[2], 'r') as file: | |
account_list = [{"id": line.split()[0], "passwd": passwd_generator(), "name": line.split()[1]} for line in file] | |
for i in xrange(len(account_list)): | |
os.system("useradd -g web -u %d -s /sbin/nologin %s" % (uid_start + i, account_list[i]["id"])) | |
os.system('echo "%s" | passwd --stdin %s' % (account_list[i]["passwd"], account_list[i]["id"])) | |
with open("passwd.txt", "w") as file: | |
for i in account_list: | |
file.write("%s %s %s\n" % (i["name"], i["id"], i["passwd"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment