Explication d'un script shell
R0ndoudou
Messages postés
41
Statut
Membre
-
zipe31 Messages postés 34620 Date d'inscription Statut Contributeur Dernière intervention -
zipe31 Messages postés 34620 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour à tous, voila je suis en 1ere année de BTS SIO et je découvre donc linux, les scripts etc...un de nos professeurs nous a donné ce script :
1.#!/bin/bash
2.
3.# Test2Arg
4.if [ -z $1 ] || [ -z $2 ]
5.then
6. echo -e "\033[31m << ERREUR DE SYNTAXE !! >>\033[0m"
7. echo "SYNTAXE : ./TESTS_SERVEURS Arg1 Arg2"
8. echo " | \'-> \"Nom du fichier journal à générer\" "
9. echo " \'-> \"Nom du fichier contenant les adresses IP à tester\" "
10. echo "Bye"
11. exit
12.fi
13.
14.# TestFileExist
15.if [ ! -f $1 ]
16.then
17. echo -e "\033[31m << ERREUR : LE FICHIER SOURCE \"$1\" N'EXISTE PAS !! >>\033[0m"
18. exit
19.fi
20.
21.#HTML
22.echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
23.<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">
24. <head></head>
25. <body>
26. <center><h1><u>TEST DU RESEAU DE L'ENTREPRISE \"SIO\"</u></h1><br/><em>Date : 'date +%d/%m/%Y' à 'date +%k:%M:%S'</em><br/><br/>" > $2
27.echo "<table width=50%>
28. <tr>
29. <td><center><strong>ADRESSE(s) IP</strong></center></td>
30. <td><center><strong>STATUS</strong></center></td>" >> $2
31.
32.echo
33.echo "------ TEST DU RESEAU DE L'ENTREPRISE \"SIO1\" ------"
34.echo " => Date : 'date +%d/%m/%Y' à" 'date +%k:%M:%S'
35.echo
36.
37.#CLIHTML
38.for ip in $(cat $1)
39.do
40. echo "<tr>" >> $2
41. echo "<td><strong>$ip</strong></td>" >> $2
42.
43. test=$(ping $ip -c 1)
44. result=$?
45.
46. if [ $result -eq 0 ]
47. then
48. echo -e " => $ip \t [ \033[32mOK\033[0m ]"
49. echo "<td style=\"background-color:green;\"><strong><center>OK</center></strong></td>" >> $2
50.
51. elif [ $result -eq 1 ]
52. then
53. echo -e " => $ip \t [ \033[31mERREUR\033[0m ]"
54. echo "<td style=\"background-color:red;\"><strong><center>ERREUR</center></strong></td>" >> $2
55.
56. fi
57.
58. echo "</tr>" >> $2
59.done
60.
61.echo "</table><br/><br/><center><h1>FIN DU TEST RESEAU</h1></center> </body> </html>" >> $2
62.
63.echo
64.echo "---------------- FIN DU TEST RESEAU ----------------"
Et donc nous devons faire son algorithme, donc donner la " signification " de chaque ligne, en langage clair...mais je vous avouerai que pour l'instant, ce ci est du chinois pour moi...quelqu'un pourrait-il m'aider à accomplir cette tâche ? merci d'avance :)
1.#!/bin/bash
2.
3.# Test2Arg
4.if [ -z $1 ] || [ -z $2 ]
5.then
6. echo -e "\033[31m << ERREUR DE SYNTAXE !! >>\033[0m"
7. echo "SYNTAXE : ./TESTS_SERVEURS Arg1 Arg2"
8. echo " | \'-> \"Nom du fichier journal à générer\" "
9. echo " \'-> \"Nom du fichier contenant les adresses IP à tester\" "
10. echo "Bye"
11. exit
12.fi
13.
14.# TestFileExist
15.if [ ! -f $1 ]
16.then
17. echo -e "\033[31m << ERREUR : LE FICHIER SOURCE \"$1\" N'EXISTE PAS !! >>\033[0m"
18. exit
19.fi
20.
21.#HTML
22.echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
23.<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">
24. <head></head>
25. <body>
26. <center><h1><u>TEST DU RESEAU DE L'ENTREPRISE \"SIO\"</u></h1><br/><em>Date : 'date +%d/%m/%Y' à 'date +%k:%M:%S'</em><br/><br/>" > $2
27.echo "<table width=50%>
28. <tr>
29. <td><center><strong>ADRESSE(s) IP</strong></center></td>
30. <td><center><strong>STATUS</strong></center></td>" >> $2
31.
32.echo
33.echo "------ TEST DU RESEAU DE L'ENTREPRISE \"SIO1\" ------"
34.echo " => Date : 'date +%d/%m/%Y' à" 'date +%k:%M:%S'
35.echo
36.
37.#CLIHTML
38.for ip in $(cat $1)
39.do
40. echo "<tr>" >> $2
41. echo "<td><strong>$ip</strong></td>" >> $2
42.
43. test=$(ping $ip -c 1)
44. result=$?
45.
46. if [ $result -eq 0 ]
47. then
48. echo -e " => $ip \t [ \033[32mOK\033[0m ]"
49. echo "<td style=\"background-color:green;\"><strong><center>OK</center></strong></td>" >> $2
50.
51. elif [ $result -eq 1 ]
52. then
53. echo -e " => $ip \t [ \033[31mERREUR\033[0m ]"
54. echo "<td style=\"background-color:red;\"><strong><center>ERREUR</center></strong></td>" >> $2
55.
56. fi
57.
58. echo "</tr>" >> $2
59.done
60.
61.echo "</table><br/><br/><center><h1>FIN DU TEST RESEAU</h1></center> </body> </html>" >> $2
62.
63.echo
64.echo "---------------- FIN DU TEST RESEAU ----------------"
Et donc nous devons faire son algorithme, donc donner la " signification " de chaque ligne, en langage clair...mais je vous avouerai que pour l'instant, ce ci est du chinois pour moi...quelqu'un pourrait-il m'aider à accomplir cette tâche ? merci d'avance :)
4 réponses
-
Salut,
Demander de l'aide pour vos exercices sur CCM
En gros, commentes toi-même le script et on te dira si c'est bon ou pas ;-)))
;-)-
Pour une explication générale, voir là ;-)
-
-
Oui je sais que la ca fait un peu " faites l'exercice à ma place " et j'aime pas spécialement, mais la dessus j'suis juste capable d'expliquer les echo ( le truc hyper dur --" ) le reste est incompréhensible pour moi =/
-
http://www-gtr.iutv.univ-paris13.fr/Cours/Mat/Systeme/TDTP2003/tp03.html
http://aral.iut-rodez.fr/fr/sanchis/enseignement/bash/index.html
https://abs.traduc.org/abs-fr/
http://www.c-sait.net/cours/scripts.php
-
-
le premier commentaire que je ferais, c'est qu'un prof qui écrit ça, ou qui donne ça sans le corrigé, devrait retourner sur les bancs de l'école !
C t'Hié
-le type ne sait pas tester le nombre d'arguments passés au script
-il fait un uuoc
-il ne sait pas tester qu'une commande réussit ou échoue
-y a même un echo mal écrit
...
j'ai oublié quelque chose ? ah! oui : je sors. -
Salut,
le reste est incompréhensible pour moi =/
La question que je me pose est, comment le professeur peut vous demander un devoir shell sans faire des cours shell?
Reprends tes cours et sûrement tu réussiras trouver des choses.
Ensuite tu pourras nous montrer pour voir ce qui ne va pas.