siotp/sio1/sisr1/70-python/creatusr.py
2022-09-29 11:52:19 +02:00

35 lines
723 B
Python
Executable File

#!/usr/bin/python3
import sys
if len(sys.argv) != 2:
print("usage: ", sys.argv[0], "<fichier>")
sys.exit(1) # nombre de parametre invalide
filename = sys.argv[1]
try:
file = open(filename , "r")
except:
msg = "erreur ouverture fichier " + filename
print(msg, file=sys.stderr)
else:
line = file.readline()
maligne = line.rstrip()
while maligne:
(login, complet) = maligne.split(":")
print (login)
print (complet)
commande="useradd --create-home --home-dir /home/"+login+ " --shell /bin/bash --comment \"" + complet + "\" " + login
login = []
line = file.readline()
maligne = line.rstrip()
print(line)
file.close()