35-script/

This commit is contained in:
Raphanaud
2021-09-30 15:45:04 +02:00
parent f84127bcc7
commit 6fbf265e6e
14 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
#!/bin/bash
set -o errexit
set -o nounset
fich='user.txt'
while read ligne
do
echo "${ligne}"
done < "${fich}"
exit 0

View File

@@ -0,0 +1,15 @@
#!/bin/bash
set -o errexit
set -o nounset
if [[ $# != 1 ]]; then
echo "usage : $0 <fichier>"
exit 1
fi
fich="$1"
while read ligne
do
echo "${ligne}"
done < "${fich}"
exit 0

View File

@@ -0,0 +1,19 @@
#!/bin/bash
set -o errexit
set -o nounset
if [[ $# != 1 ]]; then
echo "usage : $0 <fichier>"
exit 1
fi
fich="$1"
if ! [[ -r "${fich}" ]]; then
echo "$0 : erreur ouverture fichier ${fich}"
exit 2
fi
while read ligne
do
echo "${ligne}"
done < "${fich}"
exit 0

View File

@@ -0,0 +1,22 @@
#!/bin/bash
set -o errexit
set -o nounset
if [[ $# != 1 ]]; then
echo "usage : $0 <fichier>"
exit 1
fi
fich="$1"
if ! [[ -r "${fich}" ]]; then
echo "$0 : erreur ouverture fichier ${fich}"
exit 2
fi
while read ligne
do
login=$(echo "${ligne}" |cut -f1 -d':')
nom=$(echo "${ligne}" |cut -f2 -d':')
echo "$login"
echo "$nom"
done < "${fich}"
exit 0

View File

@@ -0,0 +1,28 @@
#!/bin/bash
#set -o errexit
set -o nounset
if [[ $# != 1 ]]; then
echo "usage : $0 <fichier>"
exit 1
fi
fich="$1"
if ! [[ -r "${fich}" ]]; then
echo "$0 : erreur ouverture fichier ${fich}"
exit 2
fi
while read ligne
do
login=$(echo "${ligne}" |cut -f1 -d':')
nom=$(echo "${ligne}" |cut -f2 -d':')
getent passwd "${login}" >> /dev/null
if [[ $? != 0 ]] ; then
useradd -m -d /home/${login} -c "${nom}" -s /bin/bash ${login}
else
echo "utilisateur ${login} existant"
fi
done < "${fich}"
exit 0

View File

@@ -0,0 +1,31 @@
#!/bin/bash
#set -o errexit
set -o nounset
PATH=${PATH}:/usr/sbin
if [[ $# != 1 ]]; then
echo "usage : $0 <fichier>"
exit 1
fi
fich="$1"
if ! [[ -r "${fich}" ]]; then
echo "$0 : erreur ouverture fichier ${fich}"
exit 2
fi
while read ligne
do
login=$(echo "${ligne}" |cut -f1 -d':')
nom=$(echo "${ligne}" |cut -f2 -d':')
getent passwd "${login}" >> /dev/null
if [[ $? != 0 ]] ; then
useradd -m -d /home/${login} -c "${nom}" -s /bin/bash ${login}
pw=$(pwgen 4 1)
echo "${login}:${pw}"|chpasswd
echo "${login}:${pw}" >> "${fich}.pwd"
else
echo "$0 : utilisateur ${login} existant"
fi
done < "${fich}"
exit 0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,28 @@
#!/bin/bash
#set -o errexit
set -o nounset
if [ $# != 1 ]
then
echo "usage : $0 <fichier>"
exit 1
fi
fich="$1"
if ! [[ -r "${fich}" ]]; then
echo "$0 : erreur ouverture fichier ${fich}"
exit 2
fi
while read -r ligne
do
login=$(echo "${ligne}" |cut -f1 -d':')
echo "${login}"
getent passwd "${login}" >> /dev/null
if [[ $? = 0 ]]
then
userdel -r "${login}"
fi
done < "${fich}"
exit 0

View File

@@ -0,0 +1,4 @@
lucien
claudine
robert
marcelle

View File

@@ -0,0 +1,4 @@
lucien:Lucien Dubois
claudine:Claudine Duparc
robert:Robert Macaire
marcelle:Marcelle Desforets

View File

@@ -0,0 +1,26 @@
:
:
:
:
:
:
:
:
:
:
:
:
lucien:1XfC
claudine:PT2M
robert:K4PJ
marcelle:i4WH
claudine:7Giq
robert:VO4u
marcelle:3b8S
claudine:7qzL
robert:NvV6
marcelle:7QnY
lucien:e5Hz
claudine:j9Un
robert:ZnJ6
marcelle:B7nR

View File

@@ -0,0 +1,41 @@
#!/usr/lib/python3
import sys
import subprocess
import os
nbarg = len(sys.argv)
if nbarg != 2:
print ("Nombre d'argument invalide")
exit (1)
filename = sys.argv[1]
try:
fh = open(filename, "r")
except:
print ("Fichier ", filename," inconnu")
exit (2)
else:
line = fh.readline ()
while line:
nouvline = line.rstrip()
login,nomlong = nouvline.split(':')
cmd = "sudo useradd -m -d /home/"+login+" -c \'"+ nomlong+"\' -s /bin/bash "+ login
res = os.system ("getent passwd "+login)
if res != 0:
passw = ["pwgen", "4","1"]
#passw = "pwgen 4 1"
os.system (cmd)
#mdp = str(os.system (passw))
#print (mdp)
mdp = subprocess.run(passw,capture_output=True)
mdp2 = mdp.stdout.decode("utf-8")
mdp3 = mdp2.rstrip()
print (mdp3)
ch3 = "echo "+login+":"+mdp3+"|sudo chpasswd"
print (ch3)
os.system (ch3)
os.system ("sudo echo "+login+":"+mdp3+" >> "+filename+".pwd")
else:
print ("Utilisateur "+login+" déjà éxistant")
os.system ("sudo userdel -r "+login)
line = fh.readline()
fh.close()

View File

@@ -0,0 +1,2 @@
adupont:Albert Dupont
jduroy:Jeannette Duroy

View File

@@ -0,0 +1,4 @@
adupont:0PSg
jduroy:2Sdc
adupont:Ksw4
jduroy:C0px