35-script/
This commit is contained in:
31
sio2/sisr/35-script/bash/script/crsamba7
Executable file
31
sio2/sisr/35-script/bash/script/crsamba7
Executable 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
|
||||
|
||||
|
Reference in New Issue
Block a user