Trigger script with arguments

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
Garreth
Posts: 2
Joined: Sunday 14 October 2018 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Trigger script with arguments

Post 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 4287 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!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trigger script with arguments

Post 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 4275 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Garreth
Posts: 2
Joined: Sunday 14 October 2018 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: Trigger script with arguments

Post 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.
jurgend
Posts: 9
Joined: Sunday 18 April 2021 13:08
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Trigger script with arguments

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

Who is online

Users browsing this forum: No registered users and 1 guest