Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e0686c8ed2 | |||
| 5d45c2de86 | |||
| 82b9787a10 |
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()
|
||||||
|
|
||||||
22
sisr2/sisr/35-python/delusers.py
Normal file
22
sisr2/sisr/35-python/delusers.py
Normal 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()
|
||||||
15
sisr2/sisr/35-python/occurence.py
Normal file
15
sisr2/sisr/35-python/occurence.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
chaine = str(input("saisir une chaine"))
|
||||||
|
|
||||||
|
tab = chaine.split(" ")
|
||||||
|
|
||||||
|
cptmot = {}
|
||||||
|
for mot in tab:
|
||||||
|
if mot in cptmot:
|
||||||
|
cptmot[mot] += 1
|
||||||
|
else:
|
||||||
|
cptmot[mot] = 1
|
||||||
|
|
||||||
|
for mot in cptmot.keys():
|
||||||
|
print("Mot: ",mot ," : ",cptmot[mot])
|
||||||
7
sisr2/sisr/35-python/rayon_cercle.py
Normal file
7
sisr2/sisr/35-python/rayon_cercle.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
rayon=float(input("Donner le rayon du cercle : "))
|
||||||
|
|
||||||
|
perimetre=2 * 3.141592 * rayon
|
||||||
|
|
||||||
|
print("Le perimetre du cercle est de ",perimetre)
|
||||||
20
sisr2/sisr/35-python/reglex/analog.py
Normal file
20
sisr2/sisr/35-python/reglex/analog.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
ip_vol = {}
|
||||||
|
|
||||||
|
regexp = "^(\S+) (\S+) (\S+) \[([^]]+)\] \"(\w+) (\S+).*\" (\d+) (\S+)"
|
||||||
|
for line in sys.stdin: # on lit sur l’entrée standard
|
||||||
|
line = line.rstrip () # on enleve le retour ligne
|
||||||
|
res = re.match (regexp, line)
|
||||||
|
if res:
|
||||||
|
(host, rfc931, user, date, request, url, status, byte) = res.groups()
|
||||||
|
host = res.group (1)
|
||||||
|
byte = res.group (8)
|
||||||
|
if host in ip_vol:
|
||||||
|
ip_vol[host] += int(byte)
|
||||||
|
else:
|
||||||
|
ip_vol[host] = int(byte)
|
||||||
|
|
||||||
|
for host in ip_vol.keys():
|
||||||
|
print ('host : ', host, 'volume : ', ip_vol[host])
|
||||||
29
sisr2/sisr/35-python/tableau.py
Normal file
29
sisr2/sisr/35-python/tableau.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
tab = []
|
||||||
|
|
||||||
|
for i in range (0, 4):
|
||||||
|
valeur = int(input("Saisir un nombre à inclure dans le tableau :"))
|
||||||
|
tab.append(valeur)
|
||||||
|
|
||||||
|
min = tab[0]
|
||||||
|
max = tab[0]
|
||||||
|
somme = 0
|
||||||
|
|
||||||
|
for elem in tab:
|
||||||
|
if elem < min:
|
||||||
|
min = elem
|
||||||
|
if elem > max:
|
||||||
|
max = elem
|
||||||
|
somme += elem
|
||||||
|
|
||||||
|
print("Le plus petit élément du tableau est de :",min)
|
||||||
|
print("Le plus grand élément du tableau est de :",max)
|
||||||
|
|
||||||
|
moyenne = somme /len(tab)
|
||||||
|
|
||||||
|
print("La moyenne du tazbleau est : ",moyenne)
|
||||||
|
|
||||||
|
print("Affichage du tableau :")
|
||||||
|
for i in tab:
|
||||||
|
print("Element ", i )
|
||||||
Reference in New Issue
Block a user