42 lines
989 B
Python
Executable File
42 lines
989 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import sys
|
|
|
|
#print "Nom du programme : ", sys.argv[0]
|
|
#print "Nombre d'arguments: ", len(sys.argv)
|
|
#print "Les arguments sont : " , str(sys.argv)
|
|
|
|
if len(sys.argv) !=2:
|
|
msg = "Usage : " + sys.argv[0] + " <fichier.txt>"
|
|
print (msg, file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
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)
|
|
cmd = ('getent passwd', login)
|
|
res=subprocess.run(cmd.split(),stdout=subprocess.PIPE)
|
|
commande = "useradd --create-home --home-dir /home"+ login + " --shell /bin/bash --comment \"" + complet + "\" " + login
|
|
print (commande)
|
|
print (" ")
|
|
line = file.readline()
|
|
maligne = line.rstrip()
|
|
#print (line)
|
|
file.close()
|
|
|