scripts tp crsamba
This commit is contained in:
34
sio1/sisr1/18-bash/tpbash/crsamba5
Executable file
34
sio1/sisr1/18-bash/tpbash/crsamba5
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
usage() {
|
||||
echo "usage : $0 <users.txt>"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ $# != 1 ]] ; then
|
||||
usage
|
||||
fi
|
||||
|
||||
fich=$1
|
||||
if [[ ! -r $fich ]] ; then
|
||||
echo "i$0: erreur ouverture fichier $fich"
|
||||
exit 2
|
||||
fi
|
||||
while read ligne
|
||||
do
|
||||
login=$(echo "${ligne}"|cut -f1 -d:)
|
||||
#echo $login
|
||||
nom=$(echo "${ligne}"|cut -f2 -d:)
|
||||
#echo $nom
|
||||
if ! getent passwd "${nom}" > /dev/null 2 >&1
|
||||
then
|
||||
sudo useradd -m -c "${nom}" -s /bin/bash "${login}"
|
||||
mdp=$(pwgen 6 1)
|
||||
echo "${login}:${mdp}"|sudo chpasswd
|
||||
echo "${login}:${mdp}">>${fich}.pw
|
||||
|
||||
else
|
||||
echo "${nom}" existe déja
|
||||
fi
|
||||
done < $fich
|
Reference in New Issue
Block a user