28 lines
671 B
Python
28 lines
671 B
Python
#!/usr/bin/python3
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
filename = "users.txt"
|
|
|
|
try:
|
|
fh = open(filename, "r")
|
|
except:
|
|
print ("Fichier ", filename, " inconnu")
|
|
else:
|
|
line = fh.readline ()
|
|
while line:
|
|
# use realine() to read next line
|
|
maligne = line.rstrip()
|
|
(login, name) = maligne.split(":")
|
|
hd="/home/"+login
|
|
cmds = ["userdadd", "-m", "-c", name, "-s", "/bin/bash", "-d", hd, login ]
|
|
cmd0 = ["getent", "passwd", login]
|
|
res0 = subprocess.run(cmd0,stdout=subprocess.PIPE)
|
|
print (res0)
|
|
res = subprocess.run(cmds,stdout=subprocess.PIPE)
|
|
line = fh.readline()
|
|
fh.close()
|
|
|