From bef3ed97e7d9f5d36056457ac2945c78d46c7958 Mon Sep 17 00:00:00 2001 From: louis Date: Thu, 29 Sep 2022 09:47:20 +0200 Subject: [PATCH] Creatusr v2 --- Sio2/SISR/30-python/creatusr2.py | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 Sio2/SISR/30-python/creatusr2.py diff --git a/Sio2/SISR/30-python/creatusr2.py b/Sio2/SISR/30-python/creatusr2.py new file mode 100755 index 0000000..8d738b0 --- /dev/null +++ b/Sio2/SISR/30-python/creatusr2.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 + +import sys + +#print "Nom du programme : ", sys.argv[0] +#print "Nombre d'arguments: ", len(sys.argv) +#print "Les arguments sont : " , str(sys.argv) + +if len(sys.argv) !=2: + msg = "Usage : " + sys.argv[0] + " " + print (msg, file=sys.stderr) + sys.exit(1) + +filename = sys.argv[1] + + +try: + file = open(filename , "r") + +except: + msg = "Erreur ouverture fichier " + filename + print (msg ,file=sys.stderr) + +else: + line = file.readline () + maligne = line.rstrip() + + while maligne: + (login, complet) = maligne.split(":") + print (login) + print (complet) + commande = "useradd --create-home --home-dir /home"+ login + " --shell /bin/bash --comment \"" + complet + "\" " + login + print (commande) + print (" ") + line = file.readline() + maligne = line.rstrip() + #print (line) + file.close() +