Bonjour/bonsoir à tous et toutes,

je viens vers vous car j'ai un petit exo perso à faire, qui consiste à cela :

J'ai un fichier csv qui est composé de :
Identifiant,Nom,Prenom,Service,Fonction,Permanent,
info1,Napo,Léon,info,Directeur,Oui,
info2,Scripte,Perle,info,Responsable,Oui,
info3,Scrout,Jessica,info,Employe,Oui,
info4,Martin,Henri,info,Employe,Non,
compta1,Terrieur,Alex,compta,Directeur,Oui,
compta2,Eràk,Patrique,compta,Responsable,Oui,
compta3,Personne,Jonathan,compta,Employe,Non,
compta4,Demùsset,Alfred,Compta,Employe,Non,
boss,MANVUSSA,Gérard,direction,Directeur,Oui,
info5,Terrieur,Alain,info,Employe,Non,
info4,Martin,Henri,info,Employe,Non,
comm1,MANVUSSA,Gérard,commercial,Directeur,Oui,
comm2,Despoireaux,Yvan,commercial,Employe,Oui,
comm3,Trëchere,Yvan,commercial,Employe,Non,

et je dois faire cela :

Pour chaque service, créer un répertoire commun à l’ensemble des personnes du service.
Dans le répertoire du service créer pour chaque utilisateur du service un répertoire personnel.
Créer les utilisateurs en respectant les obligations suivantes :
Pour les CDI (permanent) affecter un mot de passe et un login en mode shadow.
Pour les CDD définir un compte provisoire pour 60 jours.


du coup pour l'instant j'ai écris cela :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
#!/bin/sh
date_expire=`date -d "60 days" +%Y-%m-%d`
while IFS=',' read Identifiant Nom Prenom Service Fonction Permanent
do line="$Identifiant $Nom $Prenom $Service $Fonction $Permanent"
 
        if grep -q "$Service" "/etc/group" ;then
                echo "$Service Trouvé"
        else
                echo "creation du Groupe $Service"
                groupadd $Service;
        fi
 
        if [ ! -d "/home/$Service" ];then
                echo "Création du répertoire $Service";
                mkdir /home/$Service
                chown -R root:$Service /home/$Service
        fi
 
        if [ ! -d "/home/$Service/$Prenom$Nom" ];then
                echo "Création Répertoire $Prenom$Nom";
                mkdir /home/$Service/$Prenom$Nom
                chown -R root:$Service /home/$Service/$Prenom$Nom
        fi
 
                ##generation du password en curl ##
                #pwd=`curl --silent http://www.sethcardoza.com/api/rest/tools/random_password_generator`
        #echo "$Permanent"
        if [ $Permanent = "oui" ];then
                #echo "$Permanent"
                pwd=`curl --silent http://www.sethcardoza.com/api/rest/tools/random_password_generator`
                useradd "$Identifiant" -p "$pwd" -d "/home/$Service/$Prenom$Nom" -e "" -g "$Service"
                chown -R "$Identifiant":"$Service" "/home/$Service/$Prenom$Nom"
                else
                        useradd "$Identifiant" -p "$pwd" -d "/home/$Service/$Prenom$Nom" -e "$date_expire" -g "$Service"
                        chown -R "$Identifiant":"$Service" "/home/$Service/$Prenom$Nom"
        fi
 
 
 
done < /home/toto/fichier-edit.csv
J'arrive bien à créer les différents répertoires pour les services :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
drwxr-xr-x 24 root       root       4096 déc.  14 11:26 ..
drwxr-xr-x  5 root       commercial 4096 déc.  15 08:43 commercial
drwxr-xr-x  5 root       compta     4096 déc.  15 08:42 compta
drwxr-xr-x  3 root       Compta     4096 déc.  15 08:42 Compta
drwxr-xr-x  3 root       direction  4096 déc.  15 08:43 direction
drwxr-xr-x  7 root       info       4096 déc.  15 08:43 info
drwxr-xr-x  3 root       Service    4096 déc.  15 08:42 Service
ainsi que les répertoires de chaques utilisateurs dans le service correspondant (exemple ici pour le service "compta"):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
drwxr-xr-x 2 compta1 compta 4096 déc.  15 08:42 AlexTerrieur
drwxr-xr-x 2 compta3 compta 4096 déc.  15 08:42 JonathanPersonne
drwxr-xr-x 2 compta2 compta 4096 déc.  15 08:42 PatriqueEr?k
On constate que l'identifiant lié à l'utilisateur passe bien en paramètre lors du chown
Code : Sélectionner tout - Visualiser dans une fenêtre à part
own -R "$Identifiant":"$Service" "/home/$Service/$Prenom$Nom"
Bref mon problème se trouve dans cette partie du code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
if [ $Permanent = "oui" ];then
                #echo "$Permanent"
                pwd=`curl --silent http://www.sethcardoza.com/api/rest/tools/random_password_generator`
                useradd "$Identifiant" -p "$pwd" -d "/home/$Service/$Prenom$Nom" -e "" -g "$Service"
                chown -R "$Identifiant":"$Service" "/home/$Service/$Prenom$Nom"
                else
                        useradd "$Identifiant" -p "$pwd" -d "/home/$Service/$Prenom$Nom" -e "$date_expire" -g "$Service"
                        chown -R "$Identifiant":"$Service" "/home/$Service/$Prenom$Nom"
        fi
J'ai l’impression que dans ma boucle if il n'arrive pas à check ma variable $Permanent = "oui" et passe direct au else.
Pourtant quand je fais un echo de ma variable $Permanent au dessus de ma boucle if je constate bien que celle si contient soit oui ou non .. donc je comprends pas pourquoi il me l'a saute lors de la vérification..
Je vois pas mon erreur donc si vous pouviez m'aider .. cela pourrait être sympa