Page 1 of 1

Trigger script with arguments

Posted: Sunday 14 October 2018 23:06
by Garreth
Hello,

I wrote a simple script to control my foscam cameras motion. However there are plenty of commands available and I have two cameras of that type, so I tried to do it all in one script. As arguments I'm passing camera number and command number, it is simple and works from executing from the shell via eg. "./camera.sh 1 6"

However when I try to run it from switch using :
2018-10-14 23_03_23-Window.png
2018-10-14 23_03_23-Window.png (1.79 KiB) Viewed 5064 times
I'm getting fault:

Code: Select all

2018-10-14 22:51:29.739 Error: Error executing script command (/home/pi/domoticz/scripts/camera.sh). returned: 256
When I modify my script and remove the arguments, then running script via simple "script://camera.sh" works fine.

Is there a way to trigger scripts from switch selector with passed arguments? I could make a workaround and create like 15 different scripts doing same thing just with different camera and different command, but I hope it's possible to make it in "cleaner" way:) I've spend last hour to figure/find that out, so any help will be much appreciated:)

Thanks!

Re: Trigger script with arguments

Posted: Monday 15 October 2018 0:10
by waaren
Garreth wrote: Sunday 14 October 2018 23:06 Hello,

I wrote a simple script to control my foscam cameras motion. However there are plenty of commands available and I have two cameras of that type, so I tried to do it all in one script. As arguments I'm passing camera number and command number, it is simple and works from executing from the shell via eg. "./camera.sh 1 6"
I'm getting fault:

Code: Select all

2018-10-14 22:51:29.739 Error: Error executing script command (/home/pi/domoticz/scripts/camera.sh). returned: 256
When I modify my script and remove the arguments, then running script via simple "script://camera.sh" works fine.

Is there a way to trigger scripts from switch selector with passed arguments?
This should work with arguments.
Aantekening.png
Aantekening.png (46.95 KiB) Viewed 5052 times
bashscript:

Code: Select all

#!/bin/bash

echo $(date) $@ >> /usr/local/domotica/data/test
output after some tests

Code: Select all

Sun 14 Oct 23:56:09 CEST 2018 On 1 2 All
Sun 14 Oct 23:56:13 CEST 2018 Off 1 2 All
Sun 14 Oct 23:56:16 CEST 2018 On 1 2 All
according to this 256 might be a representation of 1 so maybe something funny is going on in your script. Is domoticz running with the same user as your test from the CLI ?

Re: Trigger script with arguments

Posted: Monday 15 October 2018 16:47
by Garreth
waaren wrote: Monday 15 October 2018 0:10 This should work with arguments.
Wow, kudos to you my friend!
Full path followed by script:/// (three slashes) did the trick :)

Thanks!

And 256 could be, because I have condition to "exit 1" when parameters are not within limits. But thats not so important to focus on that value I guess.

Re: Trigger script with arguments

Posted: Friday 18 February 2022 9:00
by jurgend
Garreth wrote: Monday 15 October 2018 16:47
waaren wrote: Monday 15 October 2018 0:10 This should work with arguments.
Wow, kudos to you my friend!
Full path followed by script:/// (three slashes) did the trick :)

Thanks!

And 256 could be, because I have condition to "exit 1" when parameters are not within limits. But thats not so important to focus on that value I guess.
I had the same error message but it was due to writing to a log file that was created by user pi :S, after removing the file and let the script create a new one it was from user root. ==> solved.

(just in case someone else has this error and can not fix it :D :-D)