From 7451653a1803e046a48f219ab8ccf4ae315d002c Mon Sep 17 00:00:00 2001 From: root Date: Fri, 4 Oct 2024 11:09:40 +0200 Subject: [PATCH] =?UTF-8?q?=09nouveau=20fichier=C2=A0:=20sio2/sisr/20-pyth?= =?UTF-8?q?on/delusers.py=20=09supprim=C3=A9=C2=A0:=20=20=20=20=20=20=20?= =?UTF-8?q?=20sio2/sisr/20-python/script1.sh=20=09modifi=C3=A9=C2=A0:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20sio2/sisr/20-python/users.txt.pw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sio2/sisr/20-python/delusers.py | 31 +++++++++++++++++++++++++++++++ sio2/sisr/20-python/script1.sh | 5 ----- sio2/sisr/20-python/users.txt.pw | 3 +++ 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 sio2/sisr/20-python/delusers.py delete mode 100644 sio2/sisr/20-python/script1.sh diff --git a/sio2/sisr/20-python/delusers.py b/sio2/sisr/20-python/delusers.py new file mode 100644 index 0000000..1e44842 --- /dev/null +++ b/sio2/sisr/20-python/delusers.py @@ -0,0 +1,31 @@ +#!/usr/bin/python3 + +import os +import sys + + +def delete_user(login, full_name): + try: + os.system(f'sudo userdel -r {login}') + print(f"Utilisateur {login} supprimer avec succès.") + except Exception as e: + print(f"Erreur lors de la suppression de l'utilisateur {login}: {e}") + +def main(filename): + try: + with open(filename, 'r') as file: + for line in file: + line = line.strip() + if line: + login, full_name = line.split(':') + delete_user(login.strip(), full_name.strip()) + except FileNotFoundError: + print(f"Le fichier {filename} n'a pas été trouvé.") + except Exception as e: + print(f"Erreur lors de la lecture du fichier {filename}: {e}") + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python deluser.py ") + else: + main(sys.argv[1]) diff --git a/sio2/sisr/20-python/script1.sh b/sio2/sisr/20-python/script1.sh deleted file mode 100644 index 3ee5e75..0000000 --- a/sio2/sisr/20-python/script1.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -pwgen 7 1 > - - diff --git a/sio2/sisr/20-python/users.txt.pw b/sio2/sisr/20-python/users.txt.pw index f43737b..fc8960d 100644 --- a/sio2/sisr/20-python/users.txt.pw +++ b/sio2/sisr/20-python/users.txt.pw @@ -1,3 +1,6 @@ t1:EeJ4gie t2:dei5Boo t3:ca1Jaig +t1:ve5foSe +t2:we6aiBo +t3:NahH6ah