Page 1 of 2

Domoticz not executing script, putty is.

Posted: Wednesday 06 July 2016 8:19
by fransiefrans
My Domoticz won't execute any sh script. in Putty the snapshots are send to telegram. When I try the same script with an on action I only see:

Code: Select all

Executing script: /home/pi/domoticz/scripts/bash/deurbel.sh
But no snapshots is send.

im using the following at on action: script:///home/pi/domoticz/scripts/bash/deurbel.sh

Re: Domoticz not executing script, putty is.

Posted: Wednesday 06 July 2016 8:40
by emme
script base path is /home/pi/domoticz/scripts so I think you should only put script://bash/deurbel.sh

Re: Domoticz not executing script, putty is.

Posted: Wednesday 06 July 2016 8:48
by Egregius
What are the permissions and owner of the file?

Re: Domoticz not executing script, putty is.

Posted: Wednesday 06 July 2016 8:49
by jannl
According to the logging, the scripts seems to be executed. Complete patch should not be the problem.

I think some path (or environment) settings in the script are not correct, so something (binary or setting) cannot be found by the script . When I am correct, the script is executed as user root (the user Domoticz is running under).

Re: Domoticz not executing script, putty is.

Posted: Wednesday 06 July 2016 16:05
by fransiefrans
Im using the following script:

Code: Select all

#!/bin/sh
#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
I used the same script on an other domoticz before and it used to work. But since I did a fresh install the script is not working in domoticz.

The rights are 777

Re: Domoticz not executing script, putty is.

Posted: Wednesday 06 July 2016 16:21
by jannl
Where are $TelegramChatId and $TempFileDir declared?

Re: Domoticz not executing script, putty is.

Posted: Wednesday 06 July 2016 16:26
by fransiefrans
I think in the domoticzdata.sh
The script is working in putty so I assume the chat id and the tempfiledir are ok

Or should I change both to a direct path?

Re: Domoticz not executing script, putty is.

Posted: Wednesday 06 July 2016 18:14
by oliviers
Maybe it's because it's a long-running script (ping + "sleep 2" + wget + curl ...), which domoticz doesn't like ....
Try to launch it in background via an intermediate script:

#!/bin/sh
/home/pi/domoticz/scripts/bash/deurbel.sh &

Re: Domoticz not executing script, putty is.

Posted: Wednesday 06 July 2016 18:19
by fransiefrans
I will give that a try later this evening.

Thanks

Re: Domoticz not executing script, putty is.

Posted: Wednesday 06 July 2016 23:12
by fransiefrans
unfortunately the smaller script is giving me the same results. In putty fine in domoticz only executing in the log.

Re: Domoticz not executing script, putty is.

Posted: Thursday 07 July 2016 15:44
by fransiefrans
I've never made a lua script before. I suppose it's possible to trigger the deurbel.sh when deurbel=on. How should I make the Lua script?

Re: Domoticz not executing script, putty is.

Posted: Thursday 07 July 2016 15:59
by jannl
My doorbell script is a lua script that calls a shellscript (os.execute with an &) that runs in the background.

Re: Domoticz not executing script, putty is.

Posted: Thursday 07 July 2016 16:03
by fransiefrans
Could u show me the script?

Re: Domoticz not executing script, putty is.

Posted: Thursday 07 July 2016 16:16
by jannl
I will post it here tonight when I am at home

Re: Domoticz not executing script, putty is.

Posted: Thursday 07 July 2016 17:52
by fransiefrans
Thank you

Re: Domoticz not executing script, putty is.

Posted: Thursday 07 July 2016 20:21
by jannl
The lua script

Code: Select all

-- Do stuff when doorbell rings

--print('Doorbell pressed')

t1 = os.date("*t")

-- In the evening set hall light on for 1 minute
if (timeofday['Nighttime']) then
        commandArray[1]={['LampGangOnder']='On FOR 1'}
end
if  (otherdevices['TweedeBelAan'] == 'On') then
        print('Ring second bell')
        commandArray[2]={['TweedeBel']='On'}
end
--Do not ring second bell at night
--save snapshot 
os.execute("wget \"http://192.168.1.5:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=voordeur&pwd=voordeur\" -O /home/pi/domoticz/www/images/voordeur.jpg;chown pi:pi /home/pi/domoticz/www/images/voordeur.jpg")
-- Send e-mail & notification when doorbell and nobody at home and send image if we install a camera sometime
if (otherdevices['IemandThuis']=='Off') then
        body="Hallo,<br><br>Aangebeld om: " .. t1.hour .. ":" .. t1.min .. "<br><br>Groetjes"
        --commandArray[3]={['SendEmail']='Iemand aan de deur#' .. body .. '#[email protected]'}
        commandArray[4]={['SendNotification']='Iemand aan de deur#' .. body ..'#0' }
        -- send mail
        os.execute("/home/pi/domoticz/scripts/stuurmail.sh &")
else
	-- blink light for additional attention
        if ( otherdevices['Lamp bijzettafel'] == 'Off' ) then
                os.execute("/home/pi/domoticz/scripts/knipper_eerst_aan.sh &")
        else
                os.execute("/home/pi/domoticz/scripts/knipper_eerst_uit.sh &")
        end
end

The actual mail script (uses muttrc)

Code: Select all

#!/bin/sh
#Mail picture
#echo "Start" > /home/pi/domoticz/scripts/mutt_log.txt
export MAIL=/var/mail/root
export MAILCHECK=60
export PATH=$PATH:usr/local/sbin
export [email protected]
export HOME=/root
mutt -s Voordeur [email protected] -a /home/pi/domoticz/www/images/voordeur.jpg < /home/pi/domoticz/scripts/voordeur_mailbody.txt >> /home/pi/domoticz/scripts/mutt_log.txt

Re: Domoticz not executing script, putty is.

Posted: Friday 08 July 2016 12:09
by fransiefrans
Can i write te lua like this?

Code: Select all

-- Do stuff when doorbell rings

--print('Doorbell pressed')

if (otherdevices['dummy']=='On') then
       os.execute("/home/pi/domoticz/scripts/bash/deurbel.sh &")
end

return commandArray

Re: Domoticz not executing script, putty is.

Posted: Friday 08 July 2016 13:15
by jannl
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

Re: Domoticz not executing script, putty is.

Posted: Friday 08 July 2016 19:09
by fransiefrans
All of a sudden no bash scripts are working.. not even in putty.

Re: Domoticz not executing script, putty is.

Posted: Friday 08 July 2016 19:23
by jannl
I suppose you get an error message?