Probleme de programmation Shell

breton_a Messages postés 10 Statut Membre -  
breton_a Messages postés 10 Statut Membre -
Yep tt le monde.

Chui pas encore au point question prog Shell... :s

G un probleme, on dirait que, dans la troisieme boucle while encapsulée, les conditions if ne sont pas prsies en comptes :(:(
Le fichier $DEST_INT n'est pas créé...

Je comprends pas pourquoi... Qqun peut m'aider ?

Merci d'avance.

ps : g mis qques echos le long du code pour voir comment se deroule le prog. je sais que c pas propre, mais je sais pas encore me servir du debugger :s

#! /bin/sh

DIR="/home/nokia/"
SOURCE="/home/nokia/nsas_audit.0"
SIGN="/home/nokia/sign.txt"
DEST="/home/nokia/num_user.txt"
DEST_FIN="/home/nokia/num_user_fin.txt"
DEST_INT="/home/nokia/num_user_int.txt"

grep "SIGN_OFF\|TIMEOUT\|SIGN_ON" $SOURCE > ${SIGN}

i=1
count=`wc -l $SIGN | cut -f6-6 -d' '`
echo "$count"

while [ $i -le $count ]
do
     nom=`head -$i $SIGN | tail -1 | tr ')' '(' | cut -f2-2 -d'('`
     type=`head -$i $SIGN | tail -1 | cut -f10-10 -d' '`

     if [ "$type" = "T=SIGN_ON" ];
     then
          echo "$nom/1/$type" >> $DEST
     else
          echo "$nom/0/$type" >> $DEST
     fi
     i=`expr $i + 1`
done

i=2

head -1 $DEST > $DEST_FIN
count=`wc -l $DEST | tr ' ' '/' | cut -f6-6 -d'/'`
echo "$count"

while [ $i -le $count ]
do
     nom=`head -$i $DEST | tail -1 | cut -f1-1 -d'/'`
     type=`head -$i $DEST | tail -1 | cut -f2-2 -d'/'`
     count_fin=`wc -l $DEST_FIN | tr ' ' '/' | cut -f7-7 -d'/'`
     j=1
     echo "$nom $type"

     while [ $j -le $count_fin ]
     do
          nom_fin=`head -$j $DEST_FIN | tail -1 | cut -f1-1 -d'/'`
          type_fin=`head -$j $DEST_FIN | tail -1 | cut -f2-2 -d'/'`
          echo "nom et type de test : $nom_fin $type_fin"
          if [ "$nom" = "$nom_fin" ]
          then
               if [ "$type" = "0" ]
               then
                    echo "type 0 ca roule"
                    echo "$nom/0" >> DEST_INT
               else
                    echo "type 1 ca roule aussi mais pas pour la meme valeur"
                    type= `expr $type_fin + 1`
                    echo "$nom/$type" >> DEST_INT
               fi
          else
               echo "$nom_fin/$type_fin" >> $DEST_INT
          fi
          j=`expr $j + 1`
     done

     cp $DEST_INT $DEST_FIN
     rm $DEST_INT
     i=`expr $i + 1`
done
A voir également:

1 réponse

breton_a Messages postés 10 Statut Membre
 
g modifié deux ou trois choses.
apparemment, il met pas a jour le fichier $DEST_INT.
j'essaie toujours, mais je vois que mon post dechaine pas les foules :p :p

++

#! /bin/sh

DIR="/home/nokia/"
SOURCE="/home/nokia/nsas_audit.0"
SIGN="/home/nokia/sign.txt"
DEST="/home/nokia/num_user.txt"
DEST_FIN="/home/nokia/num_user_fin.txt"
DEST_INT="/home/nokia/num_user_int.txt"

rm $SIGN $DEST

grep "SIGN_OFF\|TIMEOUT\|SIGN_ON" $SOURCE > ${SIGN}

i=1
count=`wc -l $SIGN | cut -f6-6 -d' '`

while [ $i -le $count ]
do
     nom=`head -$i $SIGN | tail -1 | tr ')' '(' | cut -f2-2 -d'('`
     type=`head -$i $SIGN | tail -1 | cut -f10-10 -d' '`

     if [ "$type" = "T=SIGN_ON" ];
     then
          echo "$nom/1/$type" >> $DEST
     else
          echo "$nom/0/$type" >> $DEST
     fi
     i=`expr $i + 1`
done           

echo > $DEST_FIN
head -1 $DEST >> $DEST_FIN
count=`wc -l $DEST | tr ' ' '/' | cut -f6-6 -d'/'`
echo "$count"

i=3

while [ $i -le $count ]
do
     echo > $DEST_INT
     nom=`head -$i $DEST | tail -1 | cut -f1-1 -d'/'`
     type=`head -$i $DEST | tail -1 | cut -f2-2 -d'/'`
while [ $i -le $count ]
do
     echo > $DEST_INT
     nom=`head -$i $DEST | tail -1 | cut -f1-1 -d'/'`
     type=`head -$i $DEST | tail -1 | cut -f2-2 -d'/'`
     count_fin=`wc -l $DEST_FIN | tr ' ' '/' | cut -f7-7 -d'/'`
     j=2
     echo "$nom $type $count_fin"

     while [ $j -le $count_fin ]
     do
          nom_fin=`head -$j $DEST_FIN | tail -1 | cut -f1-1 -d'/'`
          type_fin=`head -$j $DEST_FIN | tail -1 | cut -f2-2 -d'/'`
          echo "nom et type de test : $nom_fin $type_fin $nom"
          if [ "$nom" = "$nom_fin" ]
          then
               echo $nom $nom_fin   
               if [ $type -eq 0 ]  
               then     
                    echo "type 0 ca roule"  
                    echo "$nom/0" >> $DEST_INT  
               else  
                    echo "type 1 ca roule aussi mais pas pour la meme valeur"  
                    type=`expr $type_fin + 1`  
                    echo "$nom/$type" >> $DEST_INT  
               fi    
          else
               echo $nom $nom_fin  
               echo "$nom_fin/$type_fin" >> $DEST_INT    
          fi
          j=`expr $j + 1`
     done

     mv $DEST_INT $DEST_FIN
     i=`expr $i + 1`
done

rm $DEST
0