[19. April 2013] A-400 Advanced Network Setup now available | [11 Jan. 2013] Customize your A-400 Home Screen

Firmware: A-400 [13 May 2013] | C-300 [30 Nov. 2012] | A-300 [30 Nov. 2012] | C-200 [21 Jan. 2013] | A-200/A-210 [10 Aug. 2012]

Just got your NMT | WIKI has the answers | Search the forum | Forum Rules/Policy | Firmware & Official NMT News | Popcornhour manuals



User(s) browsing this thread: 1 Guest(s)
Thread Closed 
Executing a script on the server from the NMT?
02-20-2011, 04:46 AM
Post: #1
Bug Executing a script on the server from the NMT?
The problem: sleep is enabled on my media server (it's only in use a few hours a day), but obviously I want sleep disabled while I'm viewing. There's a nice applet called Caffeine which is a one-click toggle to achieve this on the (Linux) server.

I wanted to try to automate the process by using a script from the NMT. I'm already using this great script to wake my server (using WOL). Caffeine has a few command-line options which would be enough to get the job done if I could execute the script remotely.

But despite several hours of trying, I'm getting nowhere. I'm fairly new to Linux, so I'm feeling my way around. From reading here the obvious solution seemed to be using SSH (DropBear), but I just cannot get this to work, and there's actually very little on this forum about using SSH from the Popcorn to a server, it's all the other way around. I've gone through several attempts at setting up keys, and I can SSH into my server from my Windows box (using Putty), but DropBear on the Popcorn just gives me errors.

Apologies for the long intro. My question: is SSH my only option? (I can't find an RSH client for the Popcorn). Is there another way to execute scripts remotely from the Popcorn (it's a very simple one-line script, e.g. "caffeine -a")? Any advice appreciated.

For the record, the standard error message I get when I try to SSH from DropBear is: "No auth methods could be used", which suggests no matching authentication methods. But a quick Google suggests this is a common DropBear error and it seems to have many causes.
Find all posts by this user
02-20-2011, 04:49 AM
Post: #2
RE: Executing a script on the server from the NMT?
there is no reason to isntall dropbear pch has telnet enabled by default use putty select telnet and enter pch ip and you are in.
Find all posts by this user
02-20-2011, 04:54 AM (This post was last modified: 02-20-2011 04:54 AM by johnk.)
Post: #3
RE: Executing a script on the server from the NMT?
(02-20-2011 04:49 AM)halfelite Wrote:  there is no reason to isntall dropbear pch has telnet enabled by default use putty select telnet and enter pch ip and you are in.

Thanks for the quick response. As far as I understand Telnet, it won't allow me to automate the process. With SSH (using key authentication) my plan to was have a one-line script, e.g.:

SSH 192.168.x.x caffeine -a

which I could set up as a web service and execute from the remote. Can Telnet do this?
Find all posts by this user
02-21-2011, 04:35 AM (This post was last modified: 02-21-2011 06:13 PM by johnk.)
Post: #4
RE: Executing a script on the server from the NMT?
Okay, so I've put in a few more hours on this and I've got ssh to the server working. I can send commands on the command line (telnet) using ssh.

So now I'm trying to adapt the script I mentioned in the first post to include a command to disable sleep. I know nothing about scripting in Linux, so I'm learning as I go. The relevant bit of the script now looks like this:

echo -n "Sending MP to NAS"
/bin/busybox ether-wake -b [Mac address]
echo "Magic Packet Send..."
/bin sleep 20
echo sleeping....
/opt/sybhttpd/localhost.drives/HARD_DISK/Apps/DropBear/bin ssh -i [key] -l [user] 192.168.x.x 'echo $DISPLAY; export DISPLAY=:0.0; caffeine -a'
echo Caffeine


The first line (wake on lan) still works, as it does in the original script. My second (sleep) command is designed to give the WOL command time to do its job, and the third command activates the Caffeine applet on the server to disable sleep. These commands all work well on the command line (ssh via Telnet).

When I run the CGI script as a web service, however, with the Sleep and SSH commands I'm getting an error: "126: Permission denied". I don't know what would be causing this. Do I need to run those commands as root (although I am already using :8883)? Any suggestions appreciated.
Find all posts by this user
02-21-2011, 05:01 AM
Post: #5
RE: Executing a script on the server from the NMT?
does your script have execute permissions? a+x?
Find all posts by this user
02-21-2011, 03:24 PM
Post: #6
RE: Executing a script on the server from the NMT?
(02-21-2011 05:01 AM)accident Wrote:  does your script have execute permissions? a+x?

Yes, it does. The script does run, and the first command does execute, it's just the subsequent commands that fail.
Find all posts by this user
02-21-2011, 10:59 PM (This post was last modified: 02-21-2011 11:02 PM by johnk.)
Post: #7
RE: Executing a script on the server from the NMT?
Well, I've sorted this out, so just in case anyone is interested, here's a working version of the script. This wakes the server (WOL) and activates Caffeine (i.e. prevents sleep -- see first post) for four hours.

The two problems above ("Permission denied") were caused by bad paths. Firstly, the Sleep function on the Popcorn is a Busybox function, so I had to change

/bin sleep 20 to /bin/busybox sleep 20

The second one was more complicated. It seems that the script did not like having dots in the path (localhost.drives).

So I had to add the DropBear apps folder to PATH:

PATH=/share/Apps/DropBear/bin:$PATH

and then just use the ssh command in the script without a path.

So the full working script is:

Code:
#!/bin/sh

MARKER="#M_A_R_K_E_R_do_not_remove_me"


start()
{
    PATH=/share/Apps/DropBear/bin:$PATH
    echo -n "Sending MP to NAS"
    /bin/busybox ether-wake -b [MAC address]
    echo "Magic Packet Send..."
    /bin/busybox sleep 20
    echo sleeping....
    ssh -i [key] -y -g -l [login name] [remote host] 'echo $DISPLAY; export DISPLAY=:0.0; caffeine -a --time=4:00'
}


start_html()
{
    echo "Content-Type: text/html"
    echo ""
    cat <<EOF
<html>
<head>
<title>
NAS WOL started
</title>
</head>
<body>
            
EOF
}
            
end_html()
{
    cat <<EOF
</body>
</html>
EOF
}
start_html
start
end_html

exit 0

Be patient, this will takes 45 seconds or so to run. So you'll be staring at the "rotating wheel" for that long before the html page appears confirming the script has run.

One thing to add: however Caffeine is written, it doesn't return the script to a prompt, so it just hangs. This means that, on the NMT, the script would hang the machine. The neatest way to deal with this is to terminate the ssh session promptly on the server. Add these lines to the server's sshd config:

ClientAliveInterval {time interval in seconds}
ClientAliveCountMax 0


I set ClientAliveInterval to 15 seconds, so the session closes rapidly. I won't be using ssh for anything else, so this solves the problem. Remember to restart sshd.

Any questions, I'll do my best to answer.
Find all posts by this user
Thread Closed 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Faster PHP server CSI package journey4712 174 61,578 03-30-2013 01:12 PM
Last Post: o34171@rtrtr.com
  NMT remote iPhone native app. racermonoid 390 125,727 03-06-2013 08:01 PM
Last Post: mindnever
  Music Browser for NMT - Updated August, 2nd, 2011 gkreidl 14 8,017 01-19-2013 04:07 PM
Last Post: winfried_laane
  Serviio (DLNA server) RXP 3 2,893 12-30-2012 11:14 AM
Last Post: mikk
  MediatankController 1.2 for iPhone - browse and control your NMT from your phone Niels Leenheer 424 273,161 11-27-2012 03:28 PM
Last Post: jedebe
Star [Apps] Bierdopje 4 NMT PHP script SilverViper 4 1,311 11-26-2012 04:57 PM
Last Post: Djiest
  MediatankController 1.0 for Adobe AIR - browse and control your NMT from your PC Niels Leenheer 232 165,771 05-13-2012 10:48 PM
Last Post: robertazimmerman
  ftp server and upload images from ipcam defer 8 5,261 02-11-2012 04:48 PM
Last Post: vanquish99
  HTTP streaming server on A110 ? dony71 0 1,352 01-26-2012 02:48 AM
Last Post: dony71
  A-110 used like server db to store sensor data csorda 0 1,037 01-18-2012 04:06 PM
Last Post: csorda

Forum Jump: