Fin TP Shell

This commit is contained in:
Louis Déprés 2022-03-25 10:39:57 +01:00
parent 4222c35a27
commit a5451875f9
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,35 @@
#!/bin/bash
#set -e
#set -u
if [[ $# -ne 1 ]] ; then
echo "usage : $0 <fichier>"
exit 1
fi
if [[ ! -r "$1" ]] ; then
echo "$0 : erreur ouverture ${fich}"
exit 2
fi
fich=$1
while read ligne
do
echo "$ligne" | grep "^#" >> /dev/null && continue
[[ -z "$ligne" ]] && continue
login=$(echo "${ligne}"|cut -d: -f1)
nom=$(echo "${ligne}"|cut -d: -f2)
#echo "${login} ${nom}"
getent passwd "${login}" >> /dev/null
if [[ $? -ne 0 ]] ; then
sudo useradd --create-home --home-dir /home/"${login}" --shell /bin/bash --comment "${nom}" "${login}"
mdp=$(pwgen 6 1)
#echo "${mdp}"
echo "${login}:${mdp}"|chpasswd
echo "${login}:${mdp}" >> "${fich}.pwd"
else
echo "$0 : utilisateur ${login} existe deja"
fi
done < $fich

View File

@ -0,0 +1,10 @@
# Salut
lucien:Lucien Dubois
#-_-_-_-_-_-_-_-_-_-_-_-
claudine:Claudine Dupont
robert:Robert Dupond
# , j
marcelle:Marcelle Parde

View File

@ -0,0 +1,16 @@
lucien:oi6ooG
claudine:Aru6Vi
robert:ooGa5c
marcelle:lau7Eu
lucien:ca2liJ
claudine:Quoo6o
robert:LooKi9
marcelle:Iegh3b
lucien:Wah4fu
claudine:Yae3th
robert:phi1Is
marcelle:Bip8Sh
lucien:ja1EeS
claudine:za1voG
robert:UMieM3
marcelle:Emix6X