Page 1 of 3
Execute external shell script
Posted: 13 Jan 2013 19:09
by devauda
I'm trying to execute an external script on my connected raspberry pi using os.system as you proposed in the recipes:
Execute external command
You can run external commands and scripts from Z-Way. This can be used to control some external software/hardware, send E-Mails and SMS or even make SIP calls via Asterisk!
To run command append script to a scene and add the following into the script
os.system("my_favorite_program_to_play_music")
In my scene, i added:
os.system("sh /home/pi/test.sh")
(The script is working fine if executed locally on the RaspPi)
When the scene is activated, nothing happens on the RaspPi.
Can you help?
Note that the script
Posted: 13 Jan 2013 19:09
by PoltoS
Note that the script execution is done on the Z-Way side, not on Z-Connector. Hence, it is executed on our server in chroot environment, where there are no sh and bash. Of course this does not work.
The trick was for those using Z-Way as local server. We hope to release Z-Box soon, where this will work perfectly.
The only trick we can propose you is to use HTTP requests to access your Raspberry box via public IP.
Solved
Posted: 13 Jan 2013 19:09
by devauda
Thanks. I solved my problem using http request to a server with public ip. The raspberry then pool the server to get the infos (Raspberry has a private IP).
Re: Execute external shell script
Posted: 15 Apr 2015 18:59
by kimeh
I have same kind of problem.
I created "sendMail" script to /opt/z-way-server/automation folder.
Then I created toggleButton - CodeDevice and "Code for action on" is set to os.system(sendMail)
Now I tried to push toggleButton from the Widget view but nothing happens and email never sent.
I have verified that script works from razberry command line.
So what I'am doing wrong?
Re: Execute external shell script
Posted: 15 Apr 2015 19:21
by kimeh
Quick update:
I also tried os.system(/opt/z-way-server/automation), system(/opt/z-way-server/automation) and added /opt/z-way-server/automation to .syscommands file
Re: Execute external shell script
Posted: 15 Apr 2015 19:34
by pz1
You should add /opt/z-way-server/automation/yourscriptname.sh to .syscommands.
Even better to save the script in folder storage, so it will survive system upgrades.
Unfortunately after upgrades you have to restore your .syscommands file
Re: Execute external shell script
Posted: 15 Apr 2015 20:34
by kimeh
Thanks for quick reply.
I moved sendEmail script to storage folder, renamed to sendEmail.sh and also updated .syscommands file.
Still having problems.
Server log file shows:
[2015-04-15 17:31:07.469] [core] --- Code_Device_toggleButton_16 performCommand processing: {"0":"on","1":{}}
[2015-04-15 17:31:07.482] [core] Notification: error (module): Error during perform command execution: SyntaxError: Invalid flags supplied to RegExp constructor 'sendEmail'
[2015-04-15 17:31:07.501] [core] SyntaxError: Invalid flags supplied to RegExp constructor 'sendEmail'
at new RegExp (native)
at CodeDevice.eval (eval at <anonymous> (automation/modules/CodeDevice/index.js:133:14), <anonymous>:1:1)
Re: Execute external shell script
Posted: 15 Apr 2015 23:39
by dolpheen
kimeh, wrap the command name in quotes
Re: Execute external shell script
Posted: 16 Apr 2015 17:25
by kimeh
thanks, Now it works!
Re: Execute external shell script
Posted: 12 Sep 2016 10:54
by fez
Hi,
I am trying to do the same as above with a shell script but it doesn't work for me.
I call the script from my module like this:
Code: Select all
system("/opt/z-way-server/automation/storage/sendSms.sh");
I added the full path to the .syscommands (without the quotes).
When I execute the scene I get no errors, but still I fail to see the effect (no SMS).
I tested successfully the script from the command line.
Any idea what I have missed?
thanks.