This page last changed on Aug 04, 2013 by orjo.
as described in another Thread some weeks ago, i created some scripts which can be run via the OR Shell execution protocol.
In the following you`ll find the english translation from my blog-post.
Currently i`m using it with a QNAP NAS-system TS-859 which works fine. I can not guarantee that it works with other qnaps too but i`m pretty sure. Please only do this if you know what you`re doing. I`m not responsible for any kind of problems which might occure when using the scripts.
The scripts allow you to
- start your qnap via WOL.
- shutdown your qnap.
- get the current status of your qnap (ON/OFF).
- Openremote controller running on a linux-machine
To use the scripts i created the directory /scripts. All of the scripts will be put in this directory.
Starting the QNAP
Starting the QNAP will work by sending a Magic Packet over your LAN. If you don`t already have installed the WOL-Pakage on your system do it by running the follwing command:
sudo apt-get install wakeonlan
Create a new shell script with the following content and save it as e.g. wol_server.sh
Running the script
user@host:/scripts$ ./wol-server.sh 00:11:22:33:44:55
Shutting down the QNAP:
Shutting down the QNAP is a little bit more complicated. The script is run by attaching the username, the hostname of the qnap and the ssh-password.
To use this you have to enable the SSH-Service on the webinterface of your QNAP (Networking Service/Telnet|SSH)
I`m accessing my home network from outside of the lan only by using a encrypted VPN-tunnel. So for me it is no problem to attach the ssh-password from the QNAP to the script.
If someone gets access to you openremote builder, in which the password is unencrypted too, he has the Password for your qnap. If you then have any port redirections on your internet router, it`s easy to access the nas with the password. So please do this only if you know exactly what you`re doing.
For running the script successfully and redirecting the password to the ssh-session you`ll need a package called "sshpass".
sudo apt-get install sshpass
Create a new shell script with the following content and save it as e.g. shutdown-qnap.sh
sshpass -p "$password" ssh "$username"@"$hostname" /sbin/poweroff
Running the script
user@host:/scripts$ ./shutdown-qnap.sh Benutzer Hostname/IP-Adresse SSH-Passwort
At the moment there is sent an Ping-Package to the qnap. If there is an answer, the QNAP is ON otherwise it is OFF. Maybe i will add the possibility to look after a samba share and only if this is availible the status is ON.
Create a new shell script with the following content and save it as e.g. ping-remote.sh
exec="ping -c 1"
ping -c 1 $1 -w 1 >> /dev/null
if [ $? == 0 ]
When using Switch-Sensors in openremote it is important that OR wants to have "on" or "off" as return value. Be careful with the capital letters.
Running the script
When you run the following
user@host:/scripts$ ./ping-remote.sh IP-Adresse/Hostname
the script returns "on" or "off" depending on your nas is started or not.
Create a new device in the openremote designer and assign two new commands for switching on and off the qnap.
As path give the full path to the executable shell script
as parameter enter the according parameters. The ON-Command needs the MAC-Adress of the QNAP, the OFF-Command needs the QNAP-user the IP of the QNAP and the Password (seperated by blanks)
After that you can add the command to get the qnap status. In this case you need the IP-address of the QNAP as the command parameter. As against the ON/OFF-commands this command shall be executed repeating. For this behaviour give the command a polling interval e.g. 5m for 5 minutes.
After that create a new sensor which in the end calls the status and assign the previously created "status" command.
Now create a new switch and assign the sensor to this switch
New Switch in UI-Designer
In the UI-Designer put a new switch to your template and assign the above created switch as the SwitchCommand
Label for debugging purposes
If you want to have a label to display the current status, e.g. for debugging purposes, add a label and assign the created sensor and an ON/OFF-Text
After synchronizing the Builder with your local controller you will be able to start and shutdown your qnap via the webconsole or your android-tablet.
Thanks for your feedback.
Did you ever try the internal "WOL" protocol?
Posted by mredeker at Aug 05, 2013 09:27
Wonderful work, Johannes.
If you don't mind, we should move this to a more permanent location in the wiki?
Posted by juha at Aug 05, 2013 10:18
Johannes (and other QNAP users):
there's a new community contribution for QNAP that creates a QNAP install package for OpenRemote posted here: http://forum.qnap.com/viewtopic.php?f=132&t=79104 (unfortunately registration is required).
Would that be something of interest to you? Or could you take a look at it, and see how it's working, or if anything needs to be adjusted or any other feedback you might have?
Posted by juha at Aug 08, 2013 16:03
@ Markus: I didn`t try the integrated WOL-Function but i was looking for it. Maybe i`ve overlooked it. Will try if it works.
@ JUHA: Thank you, you can move it to the wiki. Definately the better location for refinding the information.
I`m using the Controller not on the QNAP. But i will have a look at it when i have free time. I will report back later if it`s working.
Posted by orjo at Aug 09, 2013 10:51
There`s a litte update.
For some reason the shutdown-script wasn`t working for me anymore. I found out that the problem lies in there that the script is called as root. The OpenRemote Controller is also started as root.
To get it working i had to tell the script to run the sshpass command as a normal user. To do this you have to update the shutdown_qnap.sh:
Only add sudo -u user (user=normal system user) in front of the shpass-command
sudo -u user sshpass -p "$password" ssh "$username"@"$hostname" /sbin/poweroff
Posted by orjo at Sep 10, 2013 18:52
Thanks for the update. I can't remember if I moved the page to the general wiki as I had promised already – will need to check. We are updating some QNAP related pages currently anyhow, will keep this on the list.
Posted by juha at Sep 13, 2013 23:01
I'm currently doing some testing on the qnap.
Regarding this i'm in contact with Pierre.
He asked me to update the Howto-Qnap pages.
I'm going to put the information to the page the next days.
Posted by orjo at Sep 14, 2013 07:08
Ok, with regards to the main QNAP how to page, go ahead.
However, the content above in this thread should be a part of a separate page, probably a sub-page of the main how-to. I can create that page structure for you if you prefer? That's where I was planning to move the content in this thread anyhow.
Posted by juha at Sep 14, 2013 10:37
That would be great. Just tell me Ehen you finished creating the page structure and i will fill in the content.
Posted by orjo at Sep 14, 2013 10:45
It is here: Remote Control QNAP Start, Shutdown and Status
Struggling a bit with the page title since it actually teaches to do three separate things but that's what I ended up with.
Posted by juha at Sep 14, 2013 10:56
i just wanted to add all information i currently have about QNAP+OR to the howto pages but i`m a little bit confused about the page titles.
I`m thinking of adding a main page for qnap where you will then find all the additional information.
Something like this:
QNAP & Openremote
- Installing OpenRemote Controller (manually) Already existing
- Installing OpenRemote Controller (automatically,QPKG) Written from me
- Remote Control QNAP with Openremote (Start,Shutdown,Status) Written from me
- Other QNAP Stuff
What do you think about this?
Posted by orjo at Sep 22, 2013 16:06
We need to work it in a way where the current OpenRemote 2.0 How To - Controller on QNAP NAS page becomes the main page. This is mainly due to how it is being referenced externally at the moment.
On the above page the introduction should stay, as well as the "Hardware" and "Configuration of the System" sections.
The steps 1 to 3 should move into their own sub-page as soon as the instruction to install from QPKG is in place. The former is then only relevant to those who want to install development releases by themselves.
The remote control QNAP should also remain the a sub-page (as it is today).
I can move the manual install steps 1-3 in their own subsection for now, until you have time to finish the QPKG steps and once those are done, I'll move the manual steps into their own sub-page.
Posted by juha at Sep 22, 2013 16:15
Done with the page structure change. Left a TODO there for QPKG.
Posted by juha at Sep 22, 2013 16:20
Or alternatively, we leave all the actual installation pages as sub-pages. So after the configuration of system section there's just links to :
- Install QPKG
- Manual Install
- Remote Cntrol
- Other QNAP stuff
Whichever you prefer. I'm fine with both. Right now the QPKG TODO however is on the main page.
Posted by juha at Sep 22, 2013 16:31
I think the second way would be better.
I`ll transfer the two pages from the qnap/OR-forum and then the page titles could be adjusted.
Is there any way to contact you via email to discuss theese things to keep the oversight in thsi thread?
Posted by orjo at Sep 22, 2013 17:00
You can email me at juha at openremote dot org. Also on skype 'juhalindfors' we have a contributors group chat that is useful for quick questions and back and forth.
Posted by juha at Sep 22, 2013 20:11