Run_Z-Agent.sh in cron

Discussions about Z-Way software and Z-Wave technology in general
Mako
Posts: 2
Joined: 28 Jan 2012 18:40

Run_Z-Agent.sh in cron

Post by Mako »

Hi
After some time I got the zwave.me usb stick and software working on my synology DS210j NAS.
When I log on to the NAS via putty terminal I can run the Run_Z-Agent.sh script and everything works fine.

I'm having trouble getting the script to run automatically either from startup (/etc/rc.local) or from /etc/crontab.

I'm not very knowledgeable in linux but I've found on google that cron uses a different environment and that if something goes wrong full paths should be added to commands. I've tried this but to no avail.

The result is that when booted up I have the following relevant processes:

/bin/sh /volume2/zwave/Run_Z-Agent.sh
/opt/bin/sleep 1 (which is in the Run_Z-Agent.sh loop)

When I start the script manually this process is included

/volume2/zwave/z-agent -s z-cloud.z-wave.me --cacert /volume2/Certificates/cacert.pem --cert /volume2/Certificates/cert.pem --key /volume2/Certificates/cert.key -d /dev/usb/ttyUSB0

And the sleep command is not a constant process.So it seems something is going wrong with calling z-agent in the loop.

Any help would be appreciated.



Mako
Posts: 2
Joined: 28 Jan 2012 18:40

I got it working by adding

Post by Mako »

I got it working by adding

LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH

to the script.
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Good that you found the solution!

Post by PoltoS »

You can also substituteLD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH
<command>by one lineLD_LIBRARY_PATH=/usr/local/lib <command>This is allowed in bash and sh. This syntax just the variable only for the executed command and not for whole shell environment.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

rc.local or cron?

Post by pz1 »

Is there a preference for either solution /etc/rc.local or in /etc/crontab? I am inclined to add it to rc.local
Since 29-12-2016 I am no longer a moderator for this forum
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

We suggest in rc.local

Post by PoltoS »

It is the right place to execute user scripts
Dvbit
Posts: 22
Joined: 05 Nov 2012 06:28

Process dying after a while

Post by Dvbit »

I compiled the z-agent on my nas (DS212) and am using the drivers installedby the Synozwave package.
I am currently not launching the agent via crontab or rc script but via telnet in background (&) but after a while the process dies.
I checked the log but, at least it seems to me, there is no sign of interruption.
The only thing that occurs to me is that the ssh session from which the script is launched expires after a while, so my suspect is that the process although launched in background "dies" with it.

Should the z-agent be launched in a script for it to be "alive"?

TX in advance
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Of course if your ssh session

Post by PoltoS »

Of course if your ssh session dies, all running background jobs will die too. This is the Unix way to do things in multiuser environment.

You have two solutions: use &, nohup and disown (this will detach the process from the terminal session completely; please refer to man pages) or use screen utility as "persistant" terminal (screen -rx to return to detached terminal session).
Dvbit
Posts: 22
Joined: 05 Nov 2012 06:28

Ty for the very quick reply.

Post by Dvbit »

Ty for the very quick reply.
And for the great software
Dvbit
Posts: 22
Joined: 05 Nov 2012 06:28

Still not working

Post by Dvbit »

Despite having added the command to start the agent in /etc/rc.local
After reboot there's no zagent process running...

I simply added the commands above to the script. If I run it manually all fine.
Rebooting , no way
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

This works for me on DS212+

Post by pz1 »

On my DS212+ I have as last line in rc.local
sh /volume1/public/zwave/Z-Connector/Unix/Run_Z-Agent.sh

The script itself is:
#!/bin/ash

cd /volume1/public/zwave/Z-Connector/Unix


while [ 1 ]
do
LD_LIBRARY_PATH=/opt/lib:/usr/local/lib ./z-agent -s z-cloud.z-wave.me --cacert ../Certificates/cacert.pem --cert ../Certificates/cert.pem --key ../Certificates/cert.key -d /dev/ttyUSB0
# substitute /dev/ttyUSB0 by /dev/ttyACM0 or another device depending on the hardware you have

sleep 1 # spare the CPU
done

NOTE: The lines in the script do wrap here. Actually there are only three lines between do and done. The last character in 'ttyUSB0' is a ZERO!
Since 29-12-2016 I am no longer a moderator for this forum
Post Reply