Domoticz not executing script, putty is.

Moderator: leecollings

fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Domoticz not executing script, putty is.

Post by jannl »

Looks like the script is not executable anymore or the shebang line is wrong or missing.
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post by fransiefrans »

I still can't figure out what the problem could be.
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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>
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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
Last edited by jvdz on Thursday 14 July 2016 21:23, edited 1 time in total.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post by fransiefrans »

when I type http://192.168.2.1:8080/camsnapshot.jpg?idx=1 in my browser, it is downloading the snapshot
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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.
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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?
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Domoticz not executing script, putty is.

Post 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
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Domoticz not executing script, putty is.

Post 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?
fransiefrans
Posts: 59
Joined: Sunday 14 June 2015 13:22
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

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

Post 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
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest