Bonjour,
J'aimerais faire un truc. J'ai un petit problème que mon Raspebrry boot sous Rasbian, il n'arrive pas démarrer un service.
Je peux le voir en exécutant cette commande
S'il n'a pas démarré, la commande me retournera
Code : Sélectionner tout - Visualiser dans une fenêtre à part journalctl -u iot-lora-gateway.service --no-pager -n 1
L'idée est de faire un script qui va être exécuté par cron toutes le 5mn et s'il lit le texte 'ERROR: [TTN] Connection to server "" failed', il va exécuter la commandeOct 21 20:54:24 iotloragateway iot-lora-gateway[668]: 20:54:24 ERROR: [TTN] Connection to server "" failed, retry in 60 seconds
Si non, on pourrait aussi analyser cette commande
Code : Sélectionner tout - Visualiser dans une fenêtre à part sudo systemctl restart iot-lora-gateway.service
et si cette commande affiche la dernière ligne que l'on voit
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 sudo systemctl status iot-lora-gateway.service ● iot-lora-gateway.service - IOT LoRa Gateway Packet Forwarder Loaded: loaded (/lib/systemd/system/iot-lora-gateway.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-10-21 20:53:53 BST; 15min ago Process: 481 ExecStartPre=/opt/iotloragateway/iot-lora-gateway-reset.sh (code=exited, status=0/SUCCESS) Main PID: 668 (iot-lora-gatewa) Tasks: 1 (limit: 2065) CGroup: /system.slice/iot-lora-gateway.service └─668 /opt/iotloragateway/iot-lora-gateway Oct 21 21:01:24 iotloragateway iot-lora-gateway[668]: src/ttn_transport.c:371:ttn_connect(): ttn_connect: sleeping() at 150, total 24 Oct 21 21:01:24 iotloragateway iot-lora-gateway[668]: src/ttn_transport.c:371:ttn_connect(): ttn_connect: sleeping() at 160, total 24 Oct 21 21:01:24 iotloragateway iot-lora-gateway[668]: src/ttn_transport.c:371:ttn_connect(): ttn_connect: sleeping() at 170, total 24 Oct 21 21:01:24 iotloragateway iot-lora-gateway[668]: src/ttn_transport.c:371:ttn_connect(): ttn_connect: sleeping() at 180, total 24 Oct 21 21:01:24 iotloragateway iot-lora-gateway[668]: src/ttn_transport.c:371:ttn_connect(): ttn_connect: sleeping() at 190, total 24 Oct 21 21:01:24 iotloragateway iot-lora-gateway[668]: src/ttn_transport.c:371:ttn_connect(): ttn_connect: sleeping() at 200, total 24 Oct 21 21:01:24 iotloragateway iot-lora-gateway[668]: src/ttn_transport.c:371:ttn_connect(): ttn_connect: sleeping() at 210, total 24 Oct 21 21:01:24 iotloragateway iot-lora-gateway[668]: src/ttn_transport.c:371:ttn_connect(): ttn_connect: sleeping() at 220, total 24 Oct 21 21:01:24 iotloragateway iot-lora-gateway[668]: src/ttn_transport.c:371:ttn_connect(): ttn_connect: sleeping() at 230, total 24 Oct 21 21:01:24 iotloragateway iot-lora-gateway[668]: 21:01:24 ERROR: [TTN] Connection to server "" failed, retry in 480 seconds
il exécute la commandeOct 21 21:01:24 iotloragateway iot-lora-gateway[668]: 21:01:24 ERROR: [TTN] Connection to server "" failed,
sudo systemctl restart iot-lora-gateway.service
Ce que je ne sais absolument pas faire, c'est comment analyser l'exécution d'une commande si la sortie contient une chaine de caractère, comme
ERROR: [TTN] Connection to server "" failed
L'idée finale est d'exécuter ce script dès que la Raspberry a démarré jusqu'à ce qu'il lise ceci
et s'il ne lit pas ceci, mais lis ceciINFO: [TTN] send status success for
il lance la commandeERROR: [TTN] Connection to server "" failed
Merci pour vos lumières
Code : Sélectionner tout - Visualiser dans une fenêtre à part sudo systemctl restart iot-lora-gateway.service
Partager