Advertisement
Guest User

Untitled

a guest
May 12th, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #must be run from server with connections to all servers on which accounts will b$
  2.  
  3. #to run bash commands, you need to import them
  4. #v3 replacement for commands
  5. import subprocess
  6. #regex
  7. import re
  8.  
  9. #get username from inputer
  10. username=input("What username do you want to create?")
  11. print(username)
  12.  
  13. #check username availability - original thoughts - programatically incorrect
  14. #checkavail=grep username /etc/passwd
  15. #print(checkavail)
  16. # if checkavail!=""
  17. # print(username) is already in use
  18. # multiacc.py
  19. # else: (might be elif)
  20. # print(username) is available
  21.  
  22. with open('/etc/passwd', 'r') as origin_file:
  23. for line in origin_file:
  24. line = re.findall(r'(username)', line)
  25. if line:
  26. line = line[0].split(':')[0]
  27. print (line)
  28. # print (origin_file)
  29.  
  30. #suggested in chat by altendky
  31.  
  32. #with open('/etc/passwd') as f: for line in f: username = line.split(':')[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement