Script en attente

Bonjour

Depuis longtemps, je pilote mes prises Belkin Wemo via des scripts. Voici le script en question:

#!/bin/bash

################################################################################
################################################################################
# Name:          wemo_control.sh
# Usage:         [IP] [ON|OFF|GETSTATE|GETSIGNALSTRENGTH|GETFRIENDLYNAME]
# Description:
# Created:       2015-07-30
# Last Modified:
# Copyright 2014, Victor Mendonca - http://wazem.org
# License: Released under the terms of the GNU GPL license v3
################################################################################
################################################################################

#-------------------------------------------------------------------------------
# Sets variables
#-------------------------------------------------------------------------------

USAGE="wemo_control.sh [IP|network] [on|off|getstate|getsignal|getname|find]"

#if [[ $# -ne 2 ]] ; then
#  echo "$USAGE"
#  exit 0
#fi

IP="$1"
CMD="$2"


#-------------------------------------------------------------------------------
# Functions
#-------------------------------------------------------------------------------

getPort () {
  PORTTEST=$(curl -s "$IP":49152 | grep "404")

  if [ "$PORTTEST" = "" ] ; then
    PORT=49153
  else
    PORT=49152
  fi
}

turnON () {
getPort
curl -0 -A -m 5 '' -X POST -H 'Accept: ' -H \
'Content-type: text/xml; charset="utf-8"' -H \
"SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data \
'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>1</BinaryState></u:SetBinaryState></s:Body></s:Envelope>' \
-s http://$IP:$PORT/upnp/control/basicevent1 | grep "<BinaryState" | cut -d">" \
-f2 | cut -d "<" -f1 | sed 's/0/OFF/g' | sed 's/1/ON/g'
}

turnOFF () {
getPort
curl -0 -A -m 5 '' -X POST -H 'Accept: ' -H \
'Content-type: text/xml; charset="utf-8"' -H \
"SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data \
'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>0</BinaryState></u:SetBinaryState></s:Body></s:Envelope>' \
-s http://$IP:$PORT/upnp/control/basicevent1 | grep "<BinaryState"  | cut \
-d">" -f2 | cut -d "<" -f1 | sed 's/0/OFF/g' | sed 's/1/ON/g'
}

getName () {
getPort
curl -0 -A -m 5 '' -X POST -H 'Accept: ' -H \
'Content-type: text/xml; charset="utf-8"' -H \
"SOAPACTION: \"urn:Belkin:service:basicevent:1#GetFriendlyName\"" --data \
'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetFriendlyName xmlns:u="urn:Belkin:service:basicevent:1"><FriendlyName></FriendlyName></u:GetFriendlyName></s:Body></s:Envelope>' \
-s http://$IP:$PORT/upnp/control/basicevent1 |     grep "<FriendlyName" | cut \
-d">" -f2 | cut -d "<" -f1
}

getState () {
getPort
curl -0 -A -m 5 '' -X POST -H 'Accept: ' -H \
'Content-type: text/xml; charset="utf-8"' -H \
"SOAPACTION: \"urn:Belkin:service:basicevent:1#GetBinaryState\"" \
--data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>1</BinaryState></u:GetBinaryState></s:Body></s:Envelope>' \
-s http://$IP:$PORT/upnp/control/basicevent1 | grep "<BinaryState"  | cut \
-d">" -f2 | cut -d "<" -f1 | sed 's/0/OFF/g' | sed 's/1/ON/g'
}

getSigStrength () {
getPort
curl -0 -A -m 5 '' -X POST -H 'Accept: ' -H \
'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#GetSignalStrength\"" \
--data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetSignalStrength xmlns:u="urn:Belkin:service:basicevent:1"><GetSignalStrength>0</GetSignalStrength></u:GetSignalStrength></s:Body></s:Envelope>' \
-s http://$IP:$PORT/upnp/control/basicevent1 | grep "<SignalStrength"  | cut \
-d">" -f2 | cut -d "<" -f1
}

findDevices () {
which nmap > /dev/null || \
  ( echo "nmap is not installed and it's needed for this option" ; exit 1 )

echo "$IP" | grep -q '\*'
if [[ $? -ne 0 ]] ; then
  echo "You need to provide a network for this option. It should be similar \
to 1.1.1.*"
  exit 1
fi

echo "Finding. This may take a while..."
DEVICES=$(nmap -p 49153 --open "$IP" | grep 'scan report for' | awk '{print $5}')
if [ "$DEVICES" ] ; then
  echo "IP           NAME"
  echo "---------------------"
  for DEVICE in $DEVICES ; do
    IP="$DEVICE"
    echo "$DEVICE $(getName )"
  done
else
  echo "Did not find any devices"
fi
}

#-------------------------------------------------------------------------------
# Starts script
#-------------------------------------------------------------------------------

case "$CMD" in
  on) turnON ;;
  off) turnOFF ;;
  getstate) getState ;;
  getsignal) getSigStrength ;;
  getname) getName ;;
  find) findDevices ;;
  *) echo "Unknown option" && exit 1 ;;
esac

exit 0

Je viens de m’apercevoir que cela ne fonctionne plus via l’interface de jeedom. Je suis donc allé en ssh pour exécuter le script, et je n’ai aucune réponse. Sur une autre machine (linux), j’ai ceci:

sh-3.2# ./wemo_control.sh 192.168.249.225 getstate
OFF

Par contre, exécuté depuis jeedom, je n’ai pas de réponse, que ce soit pour le getstate, le on ou bien le off (qui fonctionnent depuis l’autre machine). J’ai l’impression que le script tourne à l’infini. Je ne saurais dire depuis quand.
Mon script est dans /var/www/html/plugins/script/data/, et les droits sont les suivants:

-rwxrwxr-x 1 www-data www-data 5394 oct.  30  2017 wemo_control-pc1.sh

Sauriez vous me conseiller pour débugger la chose?

Merci d’avance


Matériel: raspberry pi3B+
Version Jeedom: 4.0.61
Version plugin script: 2020-06-24 09:18:07
Version Database: 10.3.23-MariaDB-0+deb10u1
Version PHP: 7.3.19-1~deb10u1
Version OS: Linux raspberrypi 5.4.61-v7+ #1339 SMP Tue Sep 1 18:45:30 BST 2020 armv7l GNU/Linux [10.4]

En fait, le script fonctionne, mais mets deux minutes à s’exécuter. Ce qui est curieux, c’est ce séquencement de deux minutes!
A chaque commande, elle est exécutée deux minutes pile après (mais uniquement pour les belkin wemo, toutes les autres commandes ne font pas cela, sur les espeasy par exemple).

J’aurais un problème avec mon script? Alors que je ne l’ai pas modifié?
Un problème avec les versions linux (j’ai fais des mises à jour dernièrement avec apt-get update et apt-get dist-upgrade, mais je ne sais pas si c’est lié).

J’avais gardé le script original (j’avais juste changé son nom). Et celui-ci fonctionnait sans problème.
Ce sont donc les copies qui, d’un coup, posaient problème. Cependant, je me demande si je n’ai pas eu des problèmes de disque, car j’ai eu d’autres soucis curieux. Disque que j’ai changé ce matin.

Maintenant, j’ai refait des copies du script original, et ça fonctionne à nouveau.

Ce sujet a été automatiquement fermé après 24 heures suivant le dernier commentaire. Aucune réponse n’est permise dorénavant.