Ajout du tp sur python
This commit is contained in:
27
sisr2/sisr/35-python/createusers.py
Normal file
27
sisr2/sisr/35-python/createusers.py
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
filename = "users.txt"
|
||||
|
||||
try:
|
||||
fh = open(filename, "r")
|
||||
except:
|
||||
print ("Fichier ", filename, " inconnu")
|
||||
else:
|
||||
line = fh.readline ()
|
||||
while line:
|
||||
# use realine() to read next line
|
||||
maligne = line.rstrip()
|
||||
(login, name) = maligne.split(":")
|
||||
hd="/home/"+login
|
||||
cmds = ["userdadd", "-m", "-c", name, "-s", "/bin/bash", "-d", hd, login ]
|
||||
cmd0 = ["getent", "passwd", login]
|
||||
res0 = subprocess.run(cmd0,stdout=subprocess.PIPE)
|
||||
print (res0)
|
||||
res = subprocess.run(cmds,stdout=subprocess.PIPE)
|
||||
line = fh.readline()
|
||||
fh.close()
|
||||
|
||||
Reference in New Issue
Block a user