33 lines
804 B
Python

#!/usr/bin/python3
import sys
import subprocess
def create_user(login, nomcomplet):
cmds = ["useradd", "-m", "-c", nomcomplet, "-s", "/bin/bash", login]
res = subprocess.run(cmds,stdout=subprocess.PIPE)
print ("createusr : utilisateur ", login, " cree")
if len(sys.argv) != 2 :
print ("usage : ", sys.argv[0], " <fichier>")
exit (1)
fichier = sys.argv[1]
try:
fh = open(fichier, "r")
except:
print (sys.argv[0], "erreur ouverture fichier ", fichier)
exit (2)
else:
line = fh.readline ()
while line:
line = line.rstrip()
# print (line)
login,nomcomplet=line.split(':')
print(login," ", nomcomplet)
# use realine() to read next line
create_user(login, nomcomplet)
line = fh.readline ()
fh.close()
exit (0)