35-script/
This commit is contained in:
parent
f84127bcc7
commit
6fbf265e6e
41
sio2/sisr/35-script/python/passusr.py
Normal file
41
sio2/sisr/35-script/python/passusr.py
Normal file
@ -0,0 +1,41 @@
|
||||
#!/usr/lib/python3
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
nbarg = len(sys.argv)
|
||||
if nbarg != 2:
|
||||
print ("Nombre d'argument invalide")
|
||||
exit (1)
|
||||
filename = sys.argv[1]
|
||||
try:
|
||||
fh = open(filename, "r")
|
||||
except:
|
||||
print ("Fichier ", filename," inconnu")
|
||||
exit (2)
|
||||
else:
|
||||
line = fh.readline ()
|
||||
while line:
|
||||
nouvline = line.rstrip()
|
||||
login,nomlong = nouvline.split(':')
|
||||
cmd = "sudo useradd -m -d /home/"+login+" -c \'"+ nomlong+"\' -s /bin/bash "+ login
|
||||
res = os.system ("getent passwd "+login)
|
||||
if res != 0:
|
||||
passw = ["pwgen", "4","1"]
|
||||
#passw = "pwgen 4 1"
|
||||
os.system (cmd)
|
||||
#mdp = str(os.system (passw))
|
||||
#print (mdp)
|
||||
mdp = subprocess.run(passw,capture_output=True)
|
||||
mdp2 = mdp.stdout.decode("utf-8")
|
||||
mdp3 = mdp2.rstrip()
|
||||
print (mdp3)
|
||||
ch3 = "echo "+login+":"+mdp3+"|sudo chpasswd"
|
||||
print (ch3)
|
||||
os.system (ch3)
|
||||
os.system ("sudo echo "+login+":"+mdp3+" >> "+filename+".pwd")
|
||||
else:
|
||||
print ("Utilisateur "+login+" déjà éxistant")
|
||||
os.system ("sudo userdel -r "+login)
|
||||
line = fh.readline()
|
||||
|
||||
fh.close()
|
2
sio2/sisr/35-script/python/user.txt
Normal file
2
sio2/sisr/35-script/python/user.txt
Normal file
@ -0,0 +1,2 @@
|
||||
adupont:Albert Dupont
|
||||
jduroy:Jeannette Duroy
|
4
sio2/sisr/35-script/python/user.txt.pwd
Normal file
4
sio2/sisr/35-script/python/user.txt.pwd
Normal file
@ -0,0 +1,4 @@
|
||||
adupont:0PSg
|
||||
jduroy:2Sdc
|
||||
adupont:Ksw4
|
||||
jduroy:C0px
|
Loading…
x
Reference in New Issue
Block a user