Trouble using scripts on Qnap NAS

Come up with a useful post-processing script? Share it here!
Post Reply
kallek
Newbie
Newbie
Posts: 12
Joined: January 8th, 2011, 5:22 pm

Trouble using scripts on Qnap NAS

Post by kallek »

I'm having trouble executing my script on a Qnap NAS. I have a simple script that turns off the NAS that looks like this:

Code: Select all

#!/bin/bash
/sbin/poweroff
It is made executable with +x and I select that it should run at the end of the queue, but nothing happens. I can run the script if I ssh and type "bash shutdown.sh".

What am I doing wrong?

User avatar
OneCD
Sr. Member
Sr. Member
Posts: 360
Joined: March 4th, 2017, 3:47 pm

Re: Trouble using scripts on Qnap NAS

Post by OneCD »

Have you tried the "Shutdown PC" action?
Stuff I like: Apache BASH CRON DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo S20 pfSense Python Raspberry Pi RAID SABnzbd SickChill Transmission Usenet VirtualBox Watcher3 XFCE

kallek
Newbie
Newbie
Posts: 12
Joined: January 8th, 2011, 5:22 pm

Re: Trouble using scripts on Qnap NAS

Post by kallek »

OneCD wrote:
March 18th, 2019, 2:11 am
Have you tried the "Shutdown PC" action?
It's not available on a NAS

User avatar
OneCD
Sr. Member
Sr. Member
Posts: 360
Joined: March 4th, 2017, 3:47 pm

Re: Trouble using scripts on Qnap NAS

Post by OneCD »

Okiedoke, just had a look at the SAB code.

These snippets are from [sabnzbd/powersup.py]:

Code: Select all

try:
    import dbus
    HAVE_DBUS = True
except ImportError:
    HAVE_DBUS = False

Code: Select all

def linux_shutdown():
    """ Make Linux system shutdown, never returns """
    if not HAVE_DBUS:
        os._exit(0)
QTS doesn't use DBUS, so SAB is unable to offer power options.

In that case, your shutdown script seems like the right way to go. ;)

I'll do some testing and see if I can get shutdown working via your script.
Stuff I like: Apache BASH CRON DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo S20 pfSense Python Raspberry Pi RAID SABnzbd SickChill Transmission Usenet VirtualBox Watcher3 XFCE

User avatar
sander
Release Testers
Release Testers
Posts: 7047
Joined: January 22nd, 2008, 2:22 pm

Re: Trouble using scripts on Qnap NAS

Post by sander »

kallek wrote:
March 18th, 2019, 1:51 am
I'm having trouble executing my script on a Qnap NAS. I have a simple script that turns off the NAS that looks like this:

Code: Select all

#!/bin/bash
/sbin/poweroff
It is made executable with +x and I select that it should run at the end of the queue, but nothing happens. I can run the script if I ssh and type "bash shutdown.sh".

What am I doing wrong?
Maybe SABnzbd is running as a user with other, less rights? Maybe n o rights to run the script and/or to run /sbin/poweroff ?

BTW Because of the shebang, no need to say "bash <blabla>"

User avatar
OneCD
Sr. Member
Sr. Member
Posts: 360
Joined: March 4th, 2017, 3:47 pm

Re: Trouble using scripts on Qnap NAS

Post by OneCD »

I created a new script called [testoff.sh] and placed it into my scripts directory. This is on a TS-559 Pro+ running QTS 4.2.6 #20181227.

This script contains:

Code: Select all

#!/usr/bin/env bash

poweroff
Made it executable:

Code: Select all

chmod +x testoff.sh
Then selected this script to be run when queue completes.

Works fine. When the last queue item completed, the NAS powered-off. :)
Stuff I like: Apache BASH CRON DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo S20 pfSense Python Raspberry Pi RAID SABnzbd SickChill Transmission Usenet VirtualBox Watcher3 XFCE

User avatar
OneCD
Sr. Member
Sr. Member
Posts: 360
Joined: March 4th, 2017, 3:47 pm

Re: Trouble using scripts on Qnap NAS

Post by OneCD »

sander wrote:
March 18th, 2019, 3:50 pm
Maybe SABnzbd is running as a user with other, less rights? Maybe n o rights to run the script and/or to run /sbin/poweroff ?
In QTS, almost all apps run with $EUID = 0. It's not ideal. :(
Stuff I like: Apache BASH CRON DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo S20 pfSense Python Raspberry Pi RAID SABnzbd SickChill Transmission Usenet VirtualBox Watcher3 XFCE

kallek
Newbie
Newbie
Posts: 12
Joined: January 8th, 2011, 5:22 pm

Re: Trouble using scripts on Qnap NAS

Post by kallek »

OneCD wrote:
March 18th, 2019, 5:01 pm
sander wrote:
March 18th, 2019, 3:50 pm
Maybe SABnzbd is running as a user with other, less rights? Maybe n o rights to run the script and/or to run /sbin/poweroff ?
In QTS, almost all apps run with $EUID = 0. It's not ideal. :(
It looks as if Sabnzbd is running as user admin. I have disabled the admin user in QTS, but I guess Sabnzbd is able to use it anyway. Is there a way of running Sabnzbd as a less privileged user? It's a little scary if someone manage to hack the web login and get admin access.

I will try your new script when I get home.

User avatar
OneCD
Sr. Member
Sr. Member
Posts: 360
Joined: March 4th, 2017, 3:47 pm

Re: Trouble using scripts on Qnap NAS

Post by OneCD »

kallek wrote:
March 19th, 2019, 1:43 am
I have disabled the admin user in QTS...
That's not a good idea. Your NAS is no better secured and it creates other issues, particularly when you’re trying to fix things. ;)

How did you install SABnzbd? Sherpa script?
kallek wrote:
March 19th, 2019, 1:43 am
Is there a way of running Sabnzbd as a less privileged user?
For now, I'm only able to support running SABnzbd as 'admin' on QTS.
kallek wrote:
March 19th, 2019, 1:43 am
It's a little scary if someone manage to hack the web login and get admin access.
Don't expose any services running on your QNAP to the Internet. Either use a reverse-proxy or VPN into your LAN.
Stuff I like: Apache BASH CRON DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo S20 pfSense Python Raspberry Pi RAID SABnzbd SickChill Transmission Usenet VirtualBox Watcher3 XFCE

kallek
Newbie
Newbie
Posts: 12
Joined: January 8th, 2011, 5:22 pm

Re: Trouble using scripts on Qnap NAS

Post by kallek »

OneCD wrote:
March 19th, 2019, 2:21 am
How did you install SABnzbd? Sherpa script?
Yes, I used the Sherpa script.
OneCD wrote:
March 19th, 2019, 2:21 am
Don't expose any services running on your QNAP to the Internet. Either use a reverse-proxy or VPN into your LAN.
Ok, So I setup a VPN on my router. Only thing I haven't got to work is Wake On LAN, so I still have to expose a UDP port. I don't know if that is such a security concern though.

I tried your script but I still can't run it from Sabnzbd. I select it to run at the end of the queue and the icon turns red. When the queue is finished nothing happens and the icon remains red and the script is still selected. If I ssh into the nas and run the script with bash shutdown.sh it works. I also enabled the admin user, but it didn't make a difference.

Permissions of the file are:

Code: Select all

-rwxrwxrwx 1 kalle  everyone         31 2019-03-19 07:49 shutdown.sh*
Is there a log file in sabnzbd that could tell me what is happening? I tried viewing the sabnzbd error log file, but it is over 500 MB and doesn't seem to be in text format.

User avatar
OneCD
Sr. Member
Sr. Member
Posts: 360
Joined: March 4th, 2017, 3:47 pm

Re: Trouble using scripts on Qnap NAS

Post by OneCD »

kallek wrote:
March 20th, 2019, 1:47 am
Yes, I used the Sherpa script.
Excellent.
OneCD wrote:
March 19th, 2019, 2:21 am
If I ssh into the nas and run the script with bash shutdown.sh it works.
As @sander mentioned above, you don't need to type:

Code: Select all

bash shutdown.sh
... if the script is executable and has a hashbang line.

Assuming you’re already in the directory containing the script, use this:

Code: Select all

./shutdown.sh
Your [shutdown.sh] script should be in [/share/Download/nzbToMedia/], correct?

Please SSH into your NAS as the 'admin' user, then run this:

Code: Select all

cat -A /share/Download/nzbToMedia/shutdown.sh
... then copypaste the result back here from your terminal window.
kallek wrote:
March 20th, 2019, 1:47 am
Is there a log file in sabnzbd that could tell me what is happening? I tried viewing the sabnzbd error log file, but it is over 500 MB and doesn't seem to be in text format.
I'll let the SAB experts answer that one. But 500MB seems a little large. ;)
Stuff I like: Apache BASH CRON DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo S20 pfSense Python Raspberry Pi RAID SABnzbd SickChill Transmission Usenet VirtualBox Watcher3 XFCE

kallek
Newbie
Newbie
Posts: 12
Joined: January 8th, 2011, 5:22 pm

Re: Trouble using scripts on Qnap NAS

Post by kallek »

OneCD wrote:
March 19th, 2019, 2:21 am
Your [shutdown.sh] script should be in [/share/Download/nzbToMedia/], correct?
I had made a new folder in [share/Download/Scripts] and pointed sabnzbd to use that folder. When I moved my script to [/share/Download/nzbToMedia/] it works! I can now execute the script from sabnzbd upon queue completion.

Thanks for all the help!

User avatar
OneCD
Sr. Member
Sr. Member
Posts: 360
Joined: March 4th, 2017, 3:47 pm

Re: Trouble using scripts on Qnap NAS

Post by OneCD »

Nicely done. :D
Stuff I like: Apache BASH CRON DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo S20 pfSense Python Raspberry Pi RAID SABnzbd SickChill Transmission Usenet VirtualBox Watcher3 XFCE

Post Reply