Problème de boucle avec retour de commande
Bonjour,
Je suis en train de travailler sur un script pour effectuer un arrêt de service et avoir un code sur l'état d'un statut.
Pour vous donner le contexte j'ai une commande pour connaitre l'état de mon service :
Code:
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
|
[root@hlzadp1tom0l bin]# /opt/ZADA0/Logiciel/XIDA/Microstrategy/home/bin/mstrctl -s IntelligenceServer gs
<status>
<computer_name>hlzadp1tom0l.yres.ytech</computer_name>
<login>csapzada0xidaissrv</login>
<process_id>15823</process_id>
<process_creation_time>2022-06-13 15:29:15.920Z</process_creation_time>
<boot_time>2021-11-24 17:37:26.000Z</boot_time>
<state>stopped</state>
<execution_mode>service</execution_mode>
<exit_code hex_value="0x00000000">0</exit_code>
<exit_message>Execution completed successfully.</exit_message>
<version_info>
<file_version>11.3.0300.11047</file_version>
<file_description>11.3.0300.11047</file_description>
<company_name>MicroStrategy Incorporated</company_name>
<original_filename>libMSTRSvr2.so~</original_filename>
<product_name>MicroStrategy 2021</product_name>
<product_version>11.3.3</product_version>
<legal_copyright>Copyright (c) 2000-2021 MicroStrategy Incorporated. All rights reserved.</legal_copyright>
<legal_trademarks>MicroStrategy (r) is a registered trademark of MicroStrategy Incorporated</legal_trademarks>
<build_machine_name>ip-10-244-21-212.internal.microstrategy.com</build_machine_name>
</version_info>
<application>
<version>11.3.0300.11047</version>
<tcp_port_number>34952</tcp_port_number>
<rest_port_number>34962</rest_port_number>
</application>
<memory>
<logging_time>2022-06-13 15:29:19.089</logging_time>
<memory_state>normal</memory_state>
</memory>
</status> |
Au travers d'un | je récupère le status du service qui est soit
<state>stopping</state>
<state>stopped</state>
<state>starting</state>
<state can_be_paused="0">running</state>
<state>unloading</state>
Ce que j'essaie de faire c'est une boucle pour savoir quand le service est correctement arrêté.
Ma concaténation fonctionne (Dans cet exemple le service est arrêté) :
Code:
1 2 3
| [root@hlzadp1tom0l bin]# /opt/ZADA0/Logiciel/XIDA/Microstrategy/home/bin/mstrctl -s IntelligenceServer gs | grep "<state>stopping</state>\|<state>stopped</state>\|<state>starting</state>\|<state>unloading</state>\|running"
<state>stopped</state> |
Mais je n'arrive pas a faire une boucle pour tester l'état vu qu'il met un certain temps a s'arrêter :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#!/bin/sh
cd /opt/$1/Logiciel/XIDA/Microstrategy/home/bin/
state=$(/opt/ZADA0/Logiciel/XIDA/Microstrategy/home/bin/mstrctl -s IntelligenceServer gs | grep "<state>stopping</state>\|<state>stopped</state>\|<state>starting</state>\|<state>unloading</state>\|running");
echo Statut actuel de MicroStrategy Intelligence Server : $state
echo Arret du service
# Arrêt du service MicroStratgy sur IntelligenceServer
./mstrctl -s IntelligenceServer stop
while [$state != "state>stopped</state>"]
do
state=$(/opt/ZADA0/Logiciel/XIDA/Microstrategy/home/bin/mstrctl -s IntelligenceServer gs | grep "<state>stopping</state>\|<state>stopped</state>\|<state>starting</state>\|<state>unloading</state>\|running");
done |
je bloque systématiquement sur ça quand j'essaie de comparer l'etat en cours du service par la recherche de mon grep avec la valeur que je souhaite voir
Code:
1 2 3 4 5 6
| [root@hlzadp1tom0l bin]# ./arret_mstr.sh
./arret_mstr.sh: line 3: cd: /opt//Logiciel/XIDA/Microstrategy/home/bin/: No such file or directory
Statut actuel de MicroStrategy Intelligence Server : <state can_be_paused="0">running</state>
Arret du service
./arret_mstr.sh: line 11: [: missing `]'
[root@hlzadp1tom0l bin]# |
Avez vous une idée s'il vous plait ?
Cordialement