From e0686c8ed2c3ddb7abfff7cdb3797d83224a0a51 Mon Sep 17 00:00:00 2001 From: "jeremy.thomas" Date: Fri, 14 Nov 2025 13:47:40 +0100 Subject: [PATCH] Ajout du tp sur python --- sisr2/sisr/35-python/createusers.py | 27 +++++++++++++++++++++++++++ sisr2/sisr/35-python/delusers.py | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 sisr2/sisr/35-python/createusers.py create mode 100644 sisr2/sisr/35-python/delusers.py diff --git a/sisr2/sisr/35-python/createusers.py b/sisr2/sisr/35-python/createusers.py new file mode 100644 index 0000000..9a1bcaf --- /dev/null +++ b/sisr2/sisr/35-python/createusers.py @@ -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() + diff --git a/sisr2/sisr/35-python/delusers.py b/sisr2/sisr/35-python/delusers.py new file mode 100644 index 0000000..d3ffda3 --- /dev/null +++ b/sisr2/sisr/35-python/delusers.py @@ -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()