Salut,
Tu peux essayer avec un script du genre :
#!/bin/bash
# script.sh
#script de mise en forme de la sortie de la commande "df -k"
#définition des variables
count=`cat disque.txt | wc -l`
ligne1=1
ligne2=4
while [ "$ligne2" -le "$count" ];do
sed -n "$ligne1","$ligne2"p disque.txt\
| tr -d '\n'\
| sed 's/Kb/Kb /g'\
| awk ' { print "Partition : "$1," Libre : "$9," Occupé : "$13," Total : "$5,\
" Pourcentage utilisation : "$17" %" } ' >> resultat.txt
ligne1=$(expr $ligne1 + 4)
ligne2=$(expr $ligne2 + 4)
doneCe qui donne en partant d'un fichier "
disque.txt" comme suit :
/home/adm (/dev/vg02/dmplv ) : 4998789 total allocated Kb
1893280 free allocated Kb
3105509 used allocated Kb
62 % allocation used
/home/lord (/dev/vg01/lordlv ) : 17776640 total allocated Kb
378152 free allocated Kb
17398488 used allocated Kb
97 % allocation used
/home (/dev/vg00/lvol5 ) : 3028736 total allocated Kb
660717 free allocated Kb
2368019 used allocated Kb
78 % allocation used
/home1 (/dev/vg02/home1lv ) : 10234528 total allocated Kb
2787174 free allocated Kb
7447354 used allocated Kb
72 % allocation used
/opt (/dev/vg00/lvol6 ) : 509305 total allocated Kb
40646 free allocated Kb
468659 used allocated Kb
92 % allocation used
/tmp (/dev/vg00/lvol4 ) : 577904 total allocated Kb
560883 free allocated Kb
17021 used allocated Kb
2 % allocation used
/usr (/dev/vg00/lvol7 ) : 1006092 total allocated Kb
313708 free allocated Kb
692384 used allocated Kb
68 % allocation used
/var (/dev/vg00/lvol8 ) : 500533 total allocated Kb
218893 free allocated Kb
281640 used allocated Kb
56 % allocation used
/stand (/dev/vg00/lvol1 ) : 75359 total allocated Kb
48398 free allocated Kb
26961 used allocated Kb
35 % allocation used
/ (/dev/vg00/lvol3 ) : 138963 total allocated Kb
66957 free allocated Kb
72006 used allocated Kb
51 % allocation used
Le résultat obtenu aprés traitement est le suivant:
cat resultat.txt
Partition : /home/adm Libre : 1893280 Occupé : 3105509 Total : 4998789 Pourcentage utilisation : 62 %
Partition : /home/lord Libre : 378152 Occupé : 17398488 Total : 17776640 Pourcentage utilisation : 97 %
Partition : /home Libre : 660717 Occupé : 2368019 Total : 3028736 Pourcentage utilisation : 78 %
Partition : /home1 Libre : 2787174 Occupé : 7447354 Total : 10234528 Pourcentage utilisation : 72 %
Partition : /opt Libre : 40646 Occupé : 468659 Total : 509305 Pourcentage utilisation : 92 %
Partition : /tmp Libre : 560883 Occupé : 17021 Total : 577904 Pourcentage utilisation : 2 %
Partition : /usr Libre : 313708 Occupé : 692384 Total : 1006092 Pourcentage utilisation : 68 %
Partition : /var Libre : 218893 Occupé : 281640 Total : 500533 Pourcentage utilisation : 56 %
Partition : /stand Libre : 48398 Occupé : 26961 Total : 75359 Pourcentage utilisation : 35 %
Partition : / Libre : 66957 Occupé : 72006 Total : 138963 Pourcentage utilisation : 51 %
Les explications :#!/bin/bash
# script.sh
# script de mise en forme de la sortie de la commande "df -k"
# définition des variables
# on récupère le nombre de ligne du fichier dans une variable
count=`cat disque.txt | wc -l`
# on initialise 2 variables pour délimiter les lignes (4 par 4)
ligne1=1
ligne2=4
# On boucle tant qu'on n'a pas atteint le nombre de ligne
while [ "$ligne2" -le "$count" ];do
# on isole les lignes 4 par 4
sed -n "$ligne1","$ligne2"p disque.txt\
# on supprime le retour chariot pour n'avoir plus qu'une seule ligne (plus facile
# pour isoler les champs avec "awk"
| tr -d '\n'\
# on ajoute un espace après "Kb" (petit inconvénient créé par la suppression
# du retour chariot)
| sed 's/Kb/Kb /g'\
# puis on fini par formater le tout avec "awk" en récupérant les champs
# qui nous intéressent
| awk ' { print "Partition : "$1," Libre : "$9," Occupé : "$13," Total : "$5,\
" Pourcentage utilisation : "$17" %" } ' >> resultat.txt
# on incrémente le contage des lignes
ligne1=$(expr $ligne1 + 4)
ligne2=$(expr $ligne2 + 4)
done;-))
Z'@+...che.JP : Zen, my Nuggets ! ;-)
Le savoir n'est bon que s'il est partagé.