modifié : creatusr/creatusr.py

This commit is contained in:
root 2024-10-04 09:13:29 +02:00
parent f3d41d6c83
commit c9237e9bf3

View File

@ -1,10 +1,32 @@
#!/usr/bin/python3
try:
fh = open("users.txt", "r")
except:
print("Fichier inconnu")
else:
line = fh.readline()
while line:
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)