Creatusr v2
This commit is contained in:
parent
72aba346b9
commit
bef3ed97e7
39
Sio2/SISR/30-python/creatusr2.py
Executable file
39
Sio2/SISR/30-python/creatusr2.py
Executable file
@ -0,0 +1,39 @@
|
||||
#!/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)
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user