Page 2 of 2

Re: Domoticz not executing script, putty is.

Posted: Friday 08 July 2016 19:49
by fransiefrans

Code: Select all

sudo  /home/pi/domoticz/scripts/bash/deurbel.sh
doesn't work anymore

Code: Select all

sh  /home/pi/domoticz/scripts/bash/deurbel.sh
is working

Re: Domoticz not executing script, putty is.

Posted: Saturday 09 July 2016 8:25
by jannl
Looks like the script is not executable anymore or the shebang line is wrong or missing.

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 20:54
by fransiefrans
I still can't figure out what the problem could be.

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 21:13
by jvdz
It's for me not totally clear what is and what isn't working but looking at the posted info I would suggest to try in your lua script:

Code: Select all

os.execute("sh /home/pi/domoticz/scripts/bash/deurbel.sh &")
and from the commandline for the sudo version:

Code: Select all

sudo  sh /home/pi/domoticz/scripts/bash/deurbel.sh
Jos

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 21:17
by fransiefrans
from commandline result:

Code: Select all

pi@raspberrypi:~$ sudo  sh /home/pi/domoticz/scripts/bash/deurbel.sh
Hallo
--2016-07-14 21:16:10--  http://192.168.2.1:8080/camsnapshot.jpg?idx=1
Connecting to 192.168.2.1:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 303356 (296K) [image/jpeg]
Saving to: ‘STDOUT’

-                   100%[=====================>] 296.25K  --.-KB/s   in 0.008s

2016-07-14 21:16:11 (34.2 MB/s) - written to stdout [303356/303356]

<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx/1.10.0</center>
</body>
</html>

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 21:21
by jvdz
What happens when you use the url in a browser on your computer?
http://192.168.2.1:8080/camsnapshot.jpg?idx=1

Scratch that.. it looks like it downloads the image. So what is returning that HTML information?
Jos

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 21:22
by fransiefrans
jannl wrote:yes, that should work. (I assume the declaration of commandArray is present).

In the deurbel.sh script, all needed variables need to be declarared/initialised
I don't understand what Jannl is saying. what should I change?

deurbel.sh:

Code: Select all

#!/bin/sh
echo "Hallo"

#SendMsgTo=$1
SendMsgTo=$TelegramChatId
#################################################################
IP="192.168.2.2"                              # IP address Camera
##########################################################
SnapFile=$TempFileDir"snapshot.jpg"
if ping -c 1 $IP > /dev/null ; then  # if IPCAM is online then:
     wget -O - http://192.168.2.1:8080/camsnapshot.jpg?idx=1 > $SnapFile
   sleep 2
   curl -s -X POST "https://api.telegram.org/bot"$TelegramBotToken"/sendPhoto" -F chat_id=$SendMsgTo -F caption="er wordt aangebeld" -F photo="@$SnapFile"
else
   curl --data 'chat_id='$SendMsgTo --data-urlencode 'text=IP-cam niet beschikbaar.' 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage'
fi

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 21:22
by fransiefrans
when I type http://192.168.2.1:8080/camsnapshot.jpg?idx=1 in my browser, it is downloading the snapshot

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 21:25
by fransiefrans
what do you mean with HTML information?

Code: Select all

sh  /home/pi/domoticz/scripts/bash/deurbel.sh
is sending me a snapshot to telegram

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 21:35
by jvdz
Ok, so the Wget is working but the Telegram isn't. Just update the script from:

Code: Select all

   curl -s -X POST "https://api.telegram.org/bot"$TelegramBotToken"/sendPhoto" -F chat_id=$SendMsgTo -F caption="er wordt aangebeld" -F photo="@$SnapFile"
to this which will echo the commandline to the console:

Code: Select all

echo curl -s -X POST "https://api.telegram.org/bot"$TelegramBotToken"/sendPhoto" -F chat_id=$SendMsgTo -F caption="er wordt aangebeld" -F photo="@$SnapFile"
curl -s -X POST "https://api.telegram.org/bot"$TelegramBotToken"/sendPhoto" -F chat_id=$SendMsgTo -F caption="er wordt aangebeld" -F photo="@$SnapFile"
This should show you whether all components in the url are filled in correctly.

Jos

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 21:43
by fransiefrans
nothing has changed.

I tried it in commandline

Code: Select all

sh  /home/pi/domoticz/scripts/bash/deurbel.sh
working showing me the same results

Code: Select all

sudo   /home/pi/domoticz/scripts/bash/deurbel.sh
not working showing me this:

Code: Select all

pi@raspberrypi:~$ sudo  /home/pi/domoticz/scripts/bash/deurbel.sh
Hallo
--2016-07-14 21:43:51--  http://192.168.2.1:8080/camsnapshot.jpg?idx=1
Connecting to 192.168.2.1:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 299897 (293K) [image/jpeg]
Saving to: ‘STDOUT’

-                                       100%[==============================================================================>] 292.87K  --.-KB/s   in 0.01s

2016-07-14 21:43:52 (24.6 MB/s) - written to stdout [299897/299897]

curl -s -X POST https://api.telegram.org/bot/sendPhoto -F chat_id= -F caption=er wordt aangebeld -F [email protected]
<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx/1.10.0</center>
</body>
</html>
it used to work with sudo command. but even then the script never worked in domoticz on/off.

and in on/off action in domoticz, it appears in the log that it is executing the script but no snapshot is send.

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 21:56
by jvdz
As you can see the details of the environment variables are missing on the URL when ran with Sudo.

you will see the difference when you run: env | grep Tele
and: sudo env | grep Tele

Jos

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 22:01
by fransiefrans
env | grep Tele is giving me telegrambotoffset, token and chat id
sudo env | grep Tele is giving me nothing


what is the difference between sudo and sh executing a file?

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 22:09
by jvdz
When shelling it without sudo it runs with USER pi.
When shelling with sudo it runs with USER root.
So guess by default the script to set the environment variables (/etc/profile.d/DomoticzData.sh) is ran with the pi userid.

Why do you need/want to use sudo anyways?

Jos

Re: Domoticz not executing script, putty is.

Posted: Thursday 14 July 2016 22:11
by fransiefrans
Ok that's clear to me now.
I don't need to use sudo. I need it to work with on/off action in domoticz :D

Re: Domoticz not executing script, putty is.

Posted: Friday 15 July 2016 6:53
by jannl
Are all the variables declared. They must be declared inside the proces space of the script.
For instance are you sure the scripts knows the value of $TelegramChatid?

Re: RE: Re: Domoticz not executing script, putty is.

Posted: Friday 15 July 2016 16:05
by fransiefrans
jannl wrote:Are all the variables declared. They must be declared inside the proces space of the script.
For instance are you sure the scripts knows the value of $TelegramChatid?
Jannl was right. With perfect help from jvdz my issue has been solved. The solution was to alter the script by declaring the variables in the top.

Code: Select all

#!/bin/sh
TelegramBotToken="123456789:AAAAAAAAAAAAA_22222222222" 
TempFileDir="/var/tmp/"
SendMsgTo="12345678"
IP="192.168.2.2"                              # IP address Camera
##########################################################
SnapFile=$TempFileDir"snapshot.jpg"
if ping -c 1 $IP > /dev/null ; then  # if IPCAM is online then:
    wget -O - http://192.168.2.1:8080/camsnapshot.jpg?idx=1 > $SnapFile
   sleep 2
   echo curl -s -X POST "https://api.telegram.org/bot"$TelegramBotToken"/sendPhoto" -F chat_id=$SendMsgTo -F caption="er wordt aangebeld" -F photo="@$SnapFile"
   curl -s -X POST "https://api.telegram.org/bot"$TelegramBotToken"/sendPhoto" -F chat_id=$SendMsgTo -F caption="er wordt aangebeld" -F photo="@$SnapFile"
else
   curl --data 'chat_id='$SendMsgTo --data-urlencode 'text=IP-cam niet beschikbaar.' 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage'
fi