Ajout du tp sur python

This commit is contained in:
2025-11-14 13:47:40 +01:00
parent 5d45c2de86
commit e0686c8ed2
2 changed files with 49 additions and 0 deletions

View 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()

View File

@@ -0,0 +1,22 @@
#!/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(":")
uncmds = ["userdel", "-r", login ]
res = subprocess.run(uncmds,stdout=subprocess.PIPE)
line = fh.readline()
fh.close()