Execute external shell script

Discussions about Z-Way software and Z-Wave technology in general
devauda
Posts: 15
Joined: 31 Dec 2012 16:37

Execute external shell script

Post 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?
User avatar
PoltoS
Posts: 7624
Joined: 26 Jan 2011 19:36

Note that the script

Post 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.
devauda
Posts: 15
Joined: 31 Dec 2012 16:37

Solved

Post 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).
kimeh
Posts: 4
Joined: 15 Apr 2015 18:00

Re: Execute external shell script

Post 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?
kimeh
Posts: 4
Joined: 15 Apr 2015 18:00

Re: Execute external shell script

Post 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
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Execute external shell script

Post 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
kimeh
Posts: 4
Joined: 15 Apr 2015 18:00

Re: Execute external shell script

Post 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)
dolpheen
Posts: 119
Joined: 10 Feb 2015 00:38

Re: Execute external shell script

Post by dolpheen »

kimeh, wrap the command name in quotes
Razberry B+ 2.0.1-rc25 on ZW500 + 15 devices / Razberry B 2.0.1-rc25 on ZW300 for test
kimeh
Posts: 4
Joined: 15 Apr 2015 18:00

Re: Execute external shell script

Post by kimeh »

thanks, Now it works!
fez
Posts: 147
Joined: 20 Jul 2015 23:03

Re: Execute external shell script

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